Change value for property item in PropertyGrid
Asked Answered
B

1

9

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.

Bialystok answered 13/8, 2012 at 16:59 Comment(1)
I think you would still end up with "(Collection)" beside your icon if you used the PaintValue method, but not sure.Pyelography
E
8

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).

Excruciation answered 13/8, 2012 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.