5

I'm trying to display the content of a datatable in my wpf datagrid

In the following post:

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

I found the code:

myDataGrid.ItemsSource = myDataTable.DefaultView;

and the behaviour is strange: it shows n empty rows where the n is correct: the query results n rows!

So why can't I see them?

Community
  • 1
  • 1
Asaf
  • 3,067
  • 11
  • 35
  • 54

2 Answers2

3

Without seeing the code, I would guess that you don't have AutoGenerateColumns set to to true. That's fine, but if you aren't auto-generating columns, you need to manually add column definitions to your data grid.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Adam Barney
  • 2,377
  • 3
  • 18
  • 24
-2

One possible solution would be to replace the DataGrid with a DataGridView and bind the DataGridView.DataSource property to the DataTable itself. As per this example:

dataGrid1.DataSource = table;

vlad
  • 4,748
  • 2
  • 30
  • 36