List directory files in a DataGrid

后端 未结 5 1908
悲哀的现实
悲哀的现实 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:59

    You can create DataGrid with one column:

    
        
            
        
    
    

    and fill it in your code like this:

    myDataGrid.ItemsSource = new DirectoryInfo(path).GetFiles();
    

    By setting ItemsSource to FileInfo[] you have option to create other columns bound to other properties for FileInfo class. This DataGrid will work with any IEnumerable assigned to ItemsSource. If it won't be a string already then ToString() will be called

提交回复
热议问题