i’m populating a datagrid programmatically but before setting the itemsource, i’m also programmatically adding the datagrid columns.
DataGridTextColumn col = new DataGridTextColumn();
col.Header = "MyCol";
col.Binding = new Binding("PropertyOFObject");
dataGrid.Columns.Add(col);
it’s easy to set the binding to the properties of my object that are concrete
however, as a property of this object, i have a list of another object type.
now, for each instance of the second object type in that list, i’d like another column to my grid, populated with a specific property of that instance of the second object type.
how would i go about doing that in this same fashion of programmatically adding the columns and setting the bindings?
If you want to bind the items of the child property to columns you can create a foreach loop which creates dynamic bindings, in one WPF question i gave an example for arrays this should be rather similar.
The key is to use a
for-loop over the length of the list and creating property-paths with injected indexer: