Why can't I bind the WPFToolkit DataGrid ItemSource to DataTable?

Edward Tanguay picture Edward Tanguay · Feb 2, 2009 · Viewed 19.2k times · Source

In a Telerik control, I was able to bind a DataTable directly to the ItemSource, but when I switched to the Codeplex WPFToolkit Datagrid:

<dg:DataGrid Name="theGrid"/>
---
theGrid.ItemsSource = dt;

I get this error:

Cannot implicitly convert type 'System.Data.DataTable' to 'System.Collections.IEnumerable'.

How can I bind the DataTable to theWPFToolkit DataGrid?

Answer

viggity picture viggity · Feb 3, 2009

I find the easiest way is:

myDataGrid.ItemsSource = myDataTable.DefaultView;

because DefaultView implements IEnumerable