0

I've encountered a problem trying to add items to WPF DataGrid. I want to load a matrix of M x N at runtime and place all the elements in the grid. However I've found only solutions that use ItemSource property or Binding for columns and as I understand they do not cope, because I need to create a predefined class. How could I accomplish that?

1 Answer 1

1

Column binding is only used when AutoGenerateColumns is set to false, so you've declaratively specified the exact columns you want and therefore have to also specify where they get their data from. (Good tutorial here).

You should set the datagrid's ItemsSource to an IEnumerable of objects - this means you can use a List, an array of your objects, or a straight DataTable.

If you need to be totally dynamic with the columns in the datagrid, then either set AutoGenerateCOlumns to true, or write some logic to programmatically create and add the columns when appropriate.

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

1 Comment

Thanks for your answer, slugster! =) But I can't find DataTable.

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.