Dynamic Propertydefinitions

May 9, 2011 at 1:39 PM


I’ve been using the property grid for a while now and it has worked very well. But as the project grows I’ve realized that I probably need to define the properties dynamically. That is, the properties names and values will be handed to me by the database and I need to display them in the property grid. The names and amount of properties may vary.

What’s your take on this? Is there a workaround or will I have to modify the property grid, and if so, do you think it would be time consuming?


May 9, 2011 at 5:48 PM

First, glad to hear you've been using, nice to get feedback.

Can you explain the data model that you're getting back from your database? Meaning typically you'd have some DTO object that is used to communicate the data and could be used in the property grid?

May 10, 2011 at 10:19 AM

* My model is a List<Table>.
* Each Table has a member List<Attribute>.
* Each Attribute has an AttributeMetadata and a Value.
* The AttributeMetadata has a Datatype, Displayname and possibly Options which is a List<string>.
* The Displayname should be displayed in the left column of the Property Grid and the Value in the right column.
* If the Datatype is Enum then the strings of the Optionslist should be displayed as a dropdown in the right column.
* I would like to be able to pick a Table from my list and get the attributes of that Table displayed in the Property Grid. Some of the tables have 10 attributes, others have up to 15.

List<Attribute> attributes

AttributeMetadata attributeMetadata
object value

string displayname
System.Type datatype
int datatypeInt
List<string> options

May 10, 2011 at 1:37 PM

Your only option would be to modify the ParseObject method on the PropertyGrid class to detect your custom entity and then parse appropriately. The good news is the grid is bound to a PropertyGridItem class which you can populate with what ever you want. The challenge you're going to face is the ability to edit/update values. You essentially would need to modify the entire core of the project to support this.

I assume the Table class is populated dynamically with information about a database table (metadata). Is there a way you could further define the model into class properties, one of which could be a collection. Then you could use the collection editor to modify the elements. The AttributeMetaData class I'm assuming is fully defined via class properties. May not be exactly what you're looking for, but might suffice without having to re-engineer the PropertyGrid.

May 18, 2011 at 8:53 AM

I’m looking in to it right now and I’ll inform you how it went after I’ve gotten a bit further. I thought I should at least give it a shoot even though it means modifying the entire core.

About the collection editor: If I have a collection in the property grid I only get a “System.Collections.Generic.List’1[System.String]”. Is there a built in editor for collections?


May 18, 2011 at 2:32 PM

It will display that as there is no way for you to modify what ToString will show, but you should still get the ... button on the right to open the CollectionEditor?