0

I have my DataGrid and I have all results inside DataTable.

DataTable dt = MakeTable();

<DataGrid Height="70" HorizontalAlignment="Left" Margin="3,1,0,0" Name="resultDataGrid" VerticalAlignment="Top" Width="475" ReadOnly="True">

I remember in Windows Form I was able to do something like:

dt.ItemSource = dt;

and it was working fine, but in WPF I am getting error: Cannot convert datasource DataTable to target IEnumerable.

Column names is always DIFFERENT, I cannot build a table manually!

How would I set it up?

Wild Goat
  • 3,509
  • 12
  • 46
  • 87

1 Answers1

1

Datatable don't support ienumrable. so you need to cast your datatable into eighter ilist or enumrable source.

try this.

DataTable dt = new DataTable();
resultDataGrid.ItemsSource =  dt.DefaultView

also set AutoGenerateColumns=true if you are not setting column in advance.

JSJ
  • 5,653
  • 3
  • 25
  • 32