开发者

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 work


You 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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜