Object instance from propertyDescriptor type
-
I've (nearly) written a custom collection implementing IBindingList and ITypedList to use a datasource for the Datagrid. The collection takes in the constructor the type of object the list will hold.
myCollection vehicleList = new MyCollection(typeof(Vehicle));
Using ITypedListGetItemProperties I then get a PropertyDescriptorCollection of Vehicle as the grid column header source. This all works fine. However I intended that Vehicle could have a collection.Public Class Vehicle { Class Vehicle(){} // lots of properties private MyCollection peopleList = new myCollection(typeof(People)) public myCollection PeopleList { get{return peopleList;} } }
when selecting this sublist as a link within the datagrid I'd like to re-use ITypedList.GetItemProperties to retrieve the public properties of type People. So far I can identify the PropertyDescriptor for peopleList and it's type of MyCollection, but I can't get the instace of peopleList needed to retrieve it's collection type of People. From which I can then build the PropertyDescriptorCollection for People. Is is possible to get the instance to which the propertyDescriptor is refering? If not I've wasted a lot of time getting this far X| -
I've (nearly) written a custom collection implementing IBindingList and ITypedList to use a datasource for the Datagrid. The collection takes in the constructor the type of object the list will hold.
myCollection vehicleList = new MyCollection(typeof(Vehicle));
Using ITypedListGetItemProperties I then get a PropertyDescriptorCollection of Vehicle as the grid column header source. This all works fine. However I intended that Vehicle could have a collection.Public Class Vehicle { Class Vehicle(){} // lots of properties private MyCollection peopleList = new myCollection(typeof(People)) public myCollection PeopleList { get{return peopleList;} } }
when selecting this sublist as a link within the datagrid I'd like to re-use ITypedList.GetItemProperties to retrieve the public properties of type People. So far I can identify the PropertyDescriptor for peopleList and it's type of MyCollection, but I can't get the instace of peopleList needed to retrieve it's collection type of People. From which I can then build the PropertyDescriptorCollection for People. Is is possible to get the instance to which the propertyDescriptor is refering? If not I've wasted a lot of time getting this far X|the last free name wrote: So far I can identify the PropertyDescriptor for peopleList and it's type of MyCollection... What exactly do you mean by "I can". Do you mean the code you've written can, you can through the debugger or through Type discovery? Please be specific. Also, you really only need to implement
ITypedList
if you need to customize the properties exposed to bindable controls. Controls that implement binding correctly (like those defined in the .NET Framework Class Library) use theBindingManagerBase
class for binding, from whichCurrencyManager
andPropertyManager
derive. If you bind your collection of objects correctly (see theDataGridTableStyle.MappingName
property for more information and an example) then you get binding for free. ImplementingIBindingList
, on the other hand, is a custom feat that really depends on your requirements, but the basic implementation you also get for free. For example, if your collection (or, rather, list) returnstrue
forIList.IsReadOnly
then items can't be added and the UI appears appropriately. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles] [My Blog]