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?

2
  • 1
    Is the DataGrid autogenerating the columns? Commented Nov 9, 2010 at 13:48
  • +1 yes I already found it... myGrid.AutoGenerateColumns = true; that indeed was the problem. Commented Nov 9, 2010 at 15:57

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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;

1 Comment

We are talking about WPF. DataGridView is a WinForms control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.