3
votes

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 doesn't work

1
There are a lot of examples out there. You must be missing something. Try following this example : switchonthecode.com/tutorials/using-the-wpf-toolkit-datagriddecyclone

1 Answers

6
votes

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