jfm*_*jor 2 c# collections propertygrid uitypeeditor
我正在尝试更改集合属性在Winforms PropertyGrid中的显示方式.
而不是拥有
MyList | (Collection) [...]
Run Code Online (Sandbox Code Playgroud)
并且必须按下按钮才能显示CollectionEditor.我正在将List扩展为ExpandableObjectConverter.但我仍然得到了[...]按钮.所以现在它看起来像这样.
[+] MyList | (2 Items) [...]
Item 1 | Value
Item 2 | Value
Run Code Online (Sandbox Code Playgroud)
最后我想替换这个[...]添加按钮.我只是不知道从哪里开始.如果我理解正确的话,CollectionEditor是我按下[...]时显示的窗口.那么我需要覆盖的对象是什么,以删除和添加我自己的按钮.
谢谢
从中继承一个新类CollectionEditor并重写GetEditStyleto返回None以防止显示"..."按钮.
同样不幸的是,您无法Add使用标准的propertygrid 添加按钮.您可以选择"...",向下箭头或无按钮.
class CustomEditor : CollectionEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用以下属性将此新编辑器应用于该属性:
[EditorAttribute(typeof(CustomEditor), typeof(UITypeEditor))]
Run Code Online (Sandbox Code Playgroud)