Binding to a DataTable

Aug 18, 2008 at 11:00 PM

I am using a proprietary database that can only be accessed through an API.  I have created an interface that translates the database data into a DataTable object.  I tried to set the ItemsSource property in code behind to the DataTable but it does not work.


Is there some way to populate the DataGrid in code behind?


Aug 18, 2008 at 11:22 PM
Does something along these lines not work for you?

 _customerDataSet =
DataTable _customerDateTable = _customerDataSet.Tables["Customers"];
 DataGrid_Standard.ItemsSource = _customerDateTable.DefaultView; 
Aug 18, 2008 at 11:31 PM

 It might be because ItemsSource is of type IEnumerable and DataTable is not. You could try using DataView (which is basically like our CollectionView) instead of DataTable.

Aug 19, 2008 at 12:36 PM
I used a DataView object to populate the ItemsSource rather than a DataTable object and it works just fine.  Thanks for the help.