views:

18

answers:

0

I'm trying to bind a datagrid to data from within a collection of a collection of the datacontext. The result should be as though all of the nested collections were just one collection with the parent collection properties still available.

For example

I have a series of products associated to an order and each product can have multiple cost values. I want to be able show this data in a datagrid with a row showing each cost for every product ideally without grouping the data.

The structure is (pseudo, I'm using VB)

Class Order
dim Reference as string
dim Order as Date
Dim Products as BindingList(of Product)
End Class

Class Product
Dim ProductName as string
Dim PartNumber as string
Dim Costs as BindingList(of Cost)
End Class

Class Cost
Dim Supplier As string
Dim Value as double
End Class

The DataGrid I'd like to see would be

ProductName | PartNumber | Supplier | Value

This would show all the costs associated to the order.

I can easily set the itemsource the datagrid to Products and create columns which bind to ProductName and PartNumber. However, how would I show the cost values and ensure that if a product had more than one cost, multiple lines for the same product was displayed?

I've seen examples which show dynamically creating extra columns for nested data but not extra rows

Hope this makes sense

Thanks