Click here to Skip to main content
15,917,329 members
Home / Discussions / C#
   

C#

 
GeneralRe: Exporting result to .csv format instead of .xlsx without using interop.excel Pin
Richard MacCutchan27-Oct-17 5:06
mveRichard MacCutchan27-Oct-17 5:06 
QuestionProgram crashes when form is refreshed Pin
Member 1274878324-Oct-17 11:55
Member 1274878324-Oct-17 11:55 
AnswerRe: Program crashes when form is refreshed Pin
Dave Kreskowiak24-Oct-17 12:08
mveDave Kreskowiak24-Oct-17 12:08 
GeneralRe: Program crashes when form is refreshed Pin
Member 1274878324-Oct-17 16:20
Member 1274878324-Oct-17 16:20 
AnswerRe: Program crashes when form is refreshed Pin
Eddy Vluggen24-Oct-17 13:33
professionalEddy Vluggen24-Oct-17 13:33 
GeneralRe: Program crashes when form is refreshed Pin
Member 1274878324-Oct-17 16:10
Member 1274878324-Oct-17 16:10 
QuestionRe: Program crashes when form is refreshed Pin
Eddy Vluggen25-Oct-17 5:09
professionalEddy Vluggen25-Oct-17 5:09 
AnswerRe: Program crashes when form is refreshed Pin
OriginalGriff24-Oct-17 20:20
mveOriginalGriff24-Oct-17 20:20 
PraiseRe: Program crashes when form is refreshed Pin
Member 1274878331-Oct-17 15:43
Member 1274878331-Oct-17 15:43 
GeneralRe: Program crashes when form is refreshed Pin
OriginalGriff31-Oct-17 20:58
mveOriginalGriff31-Oct-17 20:58 
GeneralRe: Program crashes when form is refreshed Pin
Member 127487831-Nov-17 10:38
Member 127487831-Nov-17 10:38 
QuestionIssue with WPF C# Treeview GetFiles Pin
Member 1348136124-Oct-17 8:08
Member 1348136124-Oct-17 8:08 
SuggestionRe: Issue with WPF C# Treeview GetFiles Pin
Richard Deeming24-Oct-17 9:49
mveRichard Deeming24-Oct-17 9:49 
GeneralRe: Issue with WPF C# Treeview GetFiles Pin
Member 1348136124-Oct-17 10:01
Member 1348136124-Oct-17 10:01 
GeneralRe: Issue with WPF C# Treeview GetFiles Pin
Richard Deeming25-Oct-17 1:50
mveRichard Deeming25-Oct-17 1:50 
Is this event handler actually called from anywhere? The only reference I can see is from the items that it creates, which would suggest it never runs.

If you want to add the files to the tree, then you probably want to do so from the folder_Expanded handler:
C#
void folder_Expanded(object sender, RoutedEventArgs e)
{
    TreeViewItem item = (TreeViewItem)sender;
    if (item.Items.Count == 1 && item.Items[0] == dummyNode)
    {
        item.Items.Clear();
        try
        {
            string path = item.Tag.ToString();
            
            foreach (string dir in Directory.GetDirectories(path))
            {
                TreeViewItem subitem = new TreeViewItem();
                subitem.Header = new DirectoryInfo(dir).Name;
                subitem.Tag = dir;
                subitem.FontWeight = FontWeights.Normal;
                subitem.Items.Add(dummyNode);
                subitem.Expanded += folder_Expanded;
                item.Items.Add(subitem);
            }
            
            foreach (string file in Directory.GetFiles(path))
            {
                TreeViewItem fileitem = new TreeViewItem();
                fileitem.Header = new FileInfo(file).Name;
                fileitem.Tag = file;
                fileitem.FontWeight = FontWeights.Normal;
                
                // NB: No need for the dummy item or expanded event, since files don't have children.
                
                item.Items.Add(fileitem);
            }
        }
        catch (Exception) { }
    }
}

If you want to add the files to a different control when a folder node is selected, then you'll need to do so in the SelectedItemChanged[^] event instead.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Issue with WPF C# Treeview GetFiles Pin
Member 1348136125-Oct-17 3:09
Member 1348136125-Oct-17 3:09 
GeneralRe: Issue with WPF C# Treeview GetFiles Pin
Richard Deeming25-Oct-17 3:31
mveRichard Deeming25-Oct-17 3:31 
GeneralRe: Issue with WPF C# Treeview GetFiles Pin
Member 1348136125-Oct-17 9:21
Member 1348136125-Oct-17 9:21 
GeneralRe: Issue with WPF C# Treeview GetFiles Pin
Richard Deeming26-Oct-17 1:26
mveRichard Deeming26-Oct-17 1:26 
GeneralRe: Issue with WPF C# Treeview GetFiles Pin
Member 1348136126-Oct-17 9:46
Member 1348136126-Oct-17 9:46 
Questioncrystal reports prompt login information Pin
Member 1341707224-Oct-17 2:46
Member 1341707224-Oct-17 2:46 
AnswerRe: crystal reports prompt login information Pin
Afzaal Ahmad Zeeshan24-Oct-17 3:31
professionalAfzaal Ahmad Zeeshan24-Oct-17 3:31 
QuestionWhat am i supposed to use Pin
A.Mr.Nice.Guy23-Oct-17 20:40
A.Mr.Nice.Guy23-Oct-17 20:40 
AnswerRe: What am i supposed to use Pin
Mycroft Holmes23-Oct-17 22:06
professionalMycroft Holmes23-Oct-17 22:06 
AnswerRe: What am i supposed to use Pin
OriginalGriff23-Oct-17 22:16
mveOriginalGriff23-Oct-17 22:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.