Hello,
I am attempting to implement a custom collection and wish to databind it to
a datagrid.
Currently I can successfully bind the data, but all the properties in my
custom object appear in the grid.
I wish to hide some of the columns.
I have been advised that to do this I need to provide a
PropertyDescriptionCollection with the columns that I require in the
GetProperties implementation of my custom collection.
However, although I can iterate through the custom objects properties
perfectly when I try and add or remove items from the collection I receive a
'Method Not Supported' exception.
Here is my code:
Dim pd As PropertyDescriptor
Dim t As New clsTecBE_Product
Dim pdc As PropertyDescriptorCollection
pdc = TypeDescriptor.GetProperties(t)
For Each pd In pdc
If pd.Name.ToString <> "ProductionEnd" Then
pdc.Remove(pd) 'Method not Supported' Exception fires here
End If
Next
Any ideas on why?
Many thanks for any help,
Nick
Mitch Denny - 06 Aug 2005 08:55 GMT
Your collection needs to implement ITypedList. When you implement
GetItemProperties you return your own PropertyDescriptorCollection. When you
do this you can use the DataGrid Table and Column styles to hide certain
properties in the designer. You don't need to restrict what
PropertyDescriptors are returned, you just need to return them so that the
data-binding engine knows what it is binding to - you are almost there :)

Signature
Mitch Denny
email: mitch.denny@notgartner.com
mobile: +61 (414) 610-141
blog: http://notgartner.com
skype: callto://mitchdenny
> Hello,
>
[quoted text clipped - 29 lines]
>
> Nick