Change value for property item in PropertyGrid

c#, propertygrid, winforms

Solution

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:

- Provide a custom property descriptor by deriving a class form the abstract base class `PropertyDescriptor`.

- Override abstract methods and properties. Provide a proper implementation for the `DisplayName` and description properties.

- Let your collection class implement the `ICustomTypeDescriptor` interface.

- Return a collection of custom property descriptor by the `GetProperties()` method.

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

Problem

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

Original source