Search code examples
c#bindingpropertydescriptor

Custom property descriptor and flattening hierarchies


I have a custom property descriptor that I use to support flattening object hierarchies.

To accomplish this I subclassed PropertyDescriptor and I store a linked list to the "next" (child) property that I want to retrieve the value for.

This enables me to bind subproperties to a grid(export to excel, whatever) in a "flat" manner.

eg. Grid(bound Property, Caption)

Col1:Customer.Name(Customer)
Col2:Customer.Address(Address)
Col3:Customer.OutstandingOrders.Count(Outstanding Orders)

The problem is that once I add in a column with a duplicate name, regardless of the fact it's got a unique caption it will retrieve the property for the 1st one but still put the correct header in:

Col4:Customer.Company.Name(Company)

Any ideas?


Solution

  • The problem is that once I add in a column with a duplicate name, regardless of the fact it's got a unique caption it will retrieve the property for the 1st one but still put the correct header in.

    Can you clarify that line? I've done this before, but I used the navigation path in the imaginary name - i.e. I might have the PropertyDescriptor.Name report Customer_Company_Name rather than Name, and use the .DisplayName to report something more readable.