【问题标题】:Removing "..." button from PropertyGrid collection property从 PropertyGrid 集合属性中删除“...”按钮
【发布时间】:2012-12-13 23:19:06
【问题描述】:

我正在尝试更改集合属性在 Winforms PropertyGrid 中的显示方式。

而不是拥有

MyList | (Collection) [...]

并且必须按下按钮才能显示 CollectionEditor。 我将列表扩展为 ExpandableObjectConverter。但我仍然得到 [...] 按钮。所以现在它看起来像这样。

[+] MyList | (2 Items) [...]
    Item 1 | Value
    Item 2 | Value

最终我想用这个 [...] 替换一个添加按钮。我只是不知道从哪里开始。如果我理解正确,CollectionEditor 是我按下 [...] 时显示的窗口。那么我需要覆盖什么对象来删除和添加我自己的按钮。

谢谢

【问题讨论】:

    标签: c# collections propertygrid uitypeeditor


    【解决方案1】:

    CollectionEditor 继承一个新类并覆盖GetEditStyle 以返回None 以防止“...”按钮显示。

    不幸的是,您不能使用标准属性网格添加Add 按钮。您可以选择“...”、向下箭头或无按钮。

    class CustomEditor : CollectionEditor
    {
      public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
      {
        return UITypeEditorEditStyle.None;
      }
    }
    

    您可以使用以下属性将此新编辑器应用于属性:

    [EditorAttribute(typeof(CustomEditor), typeof(UITypeEditor))]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      相关资源
      最近更新 更多