This project has moved and is read-only. For the latest updates, please go here.

PropertyGrid to use dynamic object

Apr 13, 2012 at 4:04 PM

I have used a dynamic object to be able to display the properties of a List of business objects. These objects are decorated with some attributes that I can see following the debug steps into the propertygrid component. So far so good.

The problem I have is that after I have populated my dynamic object with the proper properties I want to show, the objects attributes are getting lost. Somehow the component are ditching the attributes/not copying them over correctly to an internal object(PropertyItem?). The problem shows up when I have displayed(marked as a string with value "<Multi>") that some properties are not equal to each other when looping thru the business object properties and the string are showed in wrong Category.

When the propertyGrid are placing the fields in correct "Category", is it in the same place as you are creating the PropertyItem? I haven't figured out where in the source code you actually place the frameworkelement in the correct Category.

If someone is familiar with this component on this level, please lend a hand since its driving me nuts and probably gets me fired. ;-)

Best regards,

Gabriel Paulsson


Apr 16, 2012 at 4:34 PM
Edited Apr 16, 2012 at 4:35 PM

I would appreciate if you could provide a small sample.  It would help me to figure out what you are trying to achieve, how you are trying to achieve it and what you are expecting.


The PropertyItem is a control that will display a single property in the PropertyGrid.  The PropertyGrid use your object and not a copy of it.  The PropertyItem.Instance property contains your object and the PropertyItem.PropertyDescriptor property contains information about the property that is being targeted on your object.  When a PropertyItem is instanciate, it initializes the PropertyItem.Category property with the PropertyDescriptor.Category value.


When the PropertyGrid.SelectedObject is set, the component calls PropertyGrid.GetObjectProperties(...) to retrieve a list of PropertyItem from your object.  Eventually, it will call PropertyGridUtilities.GetCategorizedProperties(...) or PropertyGridUtilities.GetAlphabetizedProperties(...) to group/sort them out.  The following properties on PropertyItem are used for grouping and sorting: Category, PropertyOrder and DisplayName.


I hope this will help you out.

Apr 17, 2012 at 1:13 PM

I solved it by instead of hardcoding the string to use the "string.Format" method. Problem seems to follow that I just declared `object value = "String to show"` instead of `object value = string.Format(valueToShow.ToString(), value);`

Thanks for your explaination.

Gabriel Paulsson