I am working with an object which has sub objects within (see example below). I am attempting to bind a List<rootClass> to the datagrid. When I bind the List<>, in the cell that contains the subObject, I see the following value ... 'namespace.subObject' ... the string values display correctly.
Ideally I would like to see the “Description” property of the subObject in the datacell. How can I map the subObject.Description to show in the datacell?
public class subObject { int id; string description; public string Description { get { return description; } } } public class rootClass { string value1; subObject value2; string value3; public string Value1 { get { return value1; } } public subObject Value2 { get { return value2; } } public string Value3 { get { return value3; } } }
If I’m not mistaken, it shows the result of calling .ToString() on your subObject, so you can override that to return the contents of Description.
Have you tried just binding to Value1.Description? (I’m guessing it doesn’t work).
I have a class that can be used instead of List when binding, that will handle this, it implements ITypedList, which allows a collection to provide more ‘properties’ for its objects, including calculated properties.
The last version of the files I have are here:
https://gist.github.com/lassevk/64ecea836116882a5d59b0f235858044
To use:
Basically you bind to an instance of
TypedList<T>instead ofList<T>, and adjust the BindableProperties property. I have some changes in the work, including one that just builds up BindableProperties automatically as it goes, but it isn’t in the trunk yet.You can also add calculated properties, like this:
or with .NET 3.5: