9

在下图中,“MyCars”是一个集合。如果对象的属性是一个集合,则在 PropertyGrid 中,该值显示为字符串“(Collection)”,如果该项目被选中,则右侧有一个按钮。

是否可以更改“(集合)”值?如果是这样,怎么做? 我问的原因是因为我已经为将出现在我的程序的 PropertyGrid 中的对象实现了一个自定义 UITypeEditor。到目前为止,右边的按钮出现了,但文本值与属性的显示名称相同。我想要一个不同的字符串出现在那里。

示例属性网格。

编辑:对于它的价值,我知道我可以覆盖PaintValueUITypeEditor 中的方法并提供一个图标,如果我不能解决这个问题,我可能最终会这样做,但我仍然想知道是否以及如何“(集合)”文本可以更改。

4

1 回答 1

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

于 2012-08-13T17:58:14.177 回答