user589195 user589195 - 11 months ago 105
C# Question

Binding WPF datagrid to a List<List<object>>

I have a List of Lists of Objects

and im wanting to bind it to a WPF datagrid programatically.

So far I have tried:


dtgCores.ItemsSource =;


<DataGrid Name="dtgCores" Grid.Column="1">

But I just get 2 columns Capacity and Count. Could someone please advise?

I have a list of the column headers I would like to use in the format of a list aswell.

Please let me know if oyu need anymore information.

Answer Source

A datagrid is not designed for this. It needs properties for its columns (hence Capacity and Count).

You'll need to choose:

  • use another datastructure, like List<SomeClass>
  • use another Control. A nested Listbox with 2 datatemplates will probably work.