PropertyGrid: Dynamic DropDown list for Custom Class Types

This code tells your PropertyGrid control how to work with Properties which represent a custom Class

This also works dynamically, so you don’t have to create TypeConverters and UITypeEditors for each custom Class. It discerns which Property it’s representing via a Property Attribute UniqueIdetifier

First, adding the UniqueIdentifier custom Property Attribute:

Then, two POCO classes demonstrating the data objects to be used:

Note <TypeConverter(GetType(CustomClassDropDownConverter))>  This is important. Next, some sample data for Teams:

Next the TypeConverter that tells the PropertyGrid how to render the Team Class into a single string:

Finally, the UITypeEditor that produces the drop-down list in the PropertyGrid:

And that’s it. You should be able to adapt this for use with other property data types such as integers etc.

About stigzler 47 Articles
Chief crook and wattle bosher.

Be the first to comment

Leave a Reply

Your email address will not be published.


*