How to bind a DataGrid to a DataTable in C# code behind? (All controls are generated in run-time, so no XAML please)
I tried Binding(), set the DataContext, set the ItemsSource, but all doesn't work:
/* Binding() fails */
Binding bind = new Binding();
bind.Source = dataset;
bind.Path = new PropertyPath("dataset.Tables");
datagrid.SetBinding(DataSet, bind);
/* DataContext fails */
datagrid.DataContext = dataset.Tables;
/* ItemsSource fails */
datagrid.ItemsSource = dataset.Tables;
All I need to do is to Bind a DataGrid to a DataTable, so when there is new rows added to the DataTable, it will show automatically on the DataGrid.
I search all through stackoverflow and google but strangely I cannot find a solution.