user589195 user589195 - 2 months ago 20
C# Question

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

I have a List of Lists of Objects

List<List<object>>
and im wanting to bind it to a WPF datagrid programatically.

So far I have tried:

Code

dtgCores.ItemsSource = resinSystemData.data;


xaml

<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

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.