List directory files in a DataGrid

后端 未结 5 1873
悲哀的现实
悲哀的现实 2021-01-22 00:10

I have searched many topics and can\'t find an answer on using the WPF DataGrid to list file name contents from a directory. I am able to output the contents in a <

5条回答
  •  广开言路
    2021-01-22 00:53

    string [] fileEntries = Directory.GetFiles(targetDirectory);
    
    List fileList = new List();
    
    foreach (string file in fileEntries)
    {
    
    fileList.Add(new FileInfo(file));
    }
    
    datagrid.ItemsSource = fileList;
    

提交回复
热议问题