Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change value for property item in PropertyGrid

In the picture below, "MyCars" is a collection. If an object's property is a collection, then in a PropertyGrid, the value appears as the string "(Collection)" with a button to the right if the item is selected.

Is it possible to change the "(Collection)" value? If so, how? The reason I ask is because I have implemented a custom UITypeEditor for the object that will appear in the PropertyGrid in my program. So far, the button on the right appears but the text value is the same as the display name of the property. I'd like a different string to appear there.

Example propertygrid.

Edit: for what it's worth, I know I can override the PaintValue method from UITypeEditor and provide an icon, which I may end up doing if I can't solve this issue, but I'd still like to know if and how that "(Collection)" text can be changed.

like image 633
kevin628 Avatar asked Aug 13 '12 16:08

kevin628


1 Answers

This article Customized display of collection data in a PropertyGrid might be of help.


** UPDATE **

To provide a summarized version of the article (in the event of the link being unavailable), the steps involved in customizing display and description of collection content in a PropertyGrid are as follows:

  1. Provide a custom property descriptor by deriving a class form the abstract base class PropertyDescriptor.
  2. Override abstract methods and properties. Provide a proper implementation for the DisplayName and description properties.
  3. Let your collection class implement the ICustomTypeDescriptor interface.
  4. Return a collection of custom property descriptor by the GetProperties() method.
  5. Optionally use TypeConverter derived objects provided by .NET or implement your own classes to customize the textual representation of your domain classes. Assign them to the appropriate classes or properties by using the TypeConverterAttribute class.

To globalize the PropertyGrid data, property descriptors may be chained together (See also Globalized property grid).

like image 161
chridam Avatar answered Oct 13 '22 01:10

chridam