简体   繁体   中英

How to bind WPF Datagrid itemssource to Collection of Collections?

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

eg

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM