R – How to bind WPF Datagrid itemssource to Collection of Collections

datagridwpfwpfdatagridwpftoolkit

What is the best approach to bind a WPF DataGrid ItemsSource to an ObservableCollection of ObservableCollections ?

e.g.

public ObservableCollection<ObservableCollection<MyDataItem>> DataValues = new ObservableCollection<ObservableCollection<MyDataItem>>();

where MyDataItem may look like this:

public class MyDataItem
{
    public string Caption { get; set; }
    public string DataValue { get; set; }
}

I can assume the collection of collections isn't jagged, and they all contain the same number of "columns"

Is it possible to bind each column dynamically to the 'DataValue' property of the MyDataItem objects or do I need to pack the data into an easier structure to bind to?

Best Answer

This is possible by using a collection-derived class as the inner object, and implementing ICustomTypeDescriptor on it - See a similar SO question on the topic (tagged with Silverlight, but same idea)

Silverlight DataGrid - Binding to a Collection of Collections of objects.