title: How to Bind a DataGrid to a DataTable all in code behind?
body: <p>How to bind a DataGrid to a DataTable in C# code behind? (All controls are generated in run-time, so no XAML please)</p>
  
  <p>I tried Binding(), set the DataContext, set the ItemsSource, but all doesn't work:</p>
  
  <pre><code>/* 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;
  </code></pre>
  
  <p>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.</p>
  
  <p>I search all through stackoverflow and google but strangely I cannot find a solution.</p>