wpf datatable -> datagrid
I have a filled DataTable object dt and a DataGrid object declared in xaml. dt is filled in the code programatically.
What's the way to display the information in dt in the DataGrid object?
I tried
dataGrid1.DataContext = dt;
but it d开发者_运维技巧oesn't workYou can say that the DataContext is just to tell the control "you can use this data" but doesn't specify which data should it use. You can or specify the binding on your datagrid in xaml:
ItemsSource = {Binding }
( Remember to specify the columns which you need or set the AutoGenerateColumns to True)
Or you can set the itemssource in your code-behind:
dataGrid.1ItemsSource = dt;
But this will not bind the data to the DataGrid just "fire-and-show".
精彩评论