I'm trying to change the way collection properties appear in a Winforms PropertyGrid.
Instead of having
MyList | (Collection) [...]
And having to press on the button to show the CollectionEditor. I'm expanding the List as an ExpandableObjectConverter. But I still get the [...] button. So now it looks something like this.
[+] MyList | (2 Items) [...]
Item 1 | Value
Item 2 | Value
Eventually I'd like to replace this [...] for an Add button. I just don't quite know where to start. If I understand correctly, the CollectionEditor is the window displayed when I press the [...]. So what is the object I need to override to remove and add my own buttons.
Thanks
Inherit a new class from the CollectionEditor
and override the GetEditStyle
to return None
to prevent the "..." button from showing.
Also unfortunaly you can't add an Add
button using the standard propertygrid. You can choose from "...", down arrow or no button.
class CustomEditor : CollectionEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.None;
}
}
You can apply this new editor the propery using the following attribute:
[EditorAttribute(typeof(CustomEditor), typeof(UITypeEditor))]