Please read entire question first to understand where I would have the ability to reset the default value of a property.
When defining a custom
You can create your own collection editor inheriting CollectionEditor class and then override CreateCollectionForm method, find property grid in the collection editor form and then register a ContextMenuStrip
containing a Reset menu item for property grid, then reset the property using ResetSelectedProperty:
public class MyCollectionEditor : CollectionEditor
{
public MyCollectionEditor() : base(typeof(Collection<MyElement>)) { }
protected override CollectionForm CreateCollectionForm()
{
var form = base.CreateCollectionForm();
var grid = form.Controls.Find("propertyBrowser", true).First() as PropertyGrid;
var menu = new ContextMenuStrip();
menu.Items.Add("Reset", null, (s, e) => { grid.ResetSelectedProperty(); });
//Enable or disable Reset menu based on selected property
menu.Opening += (s, e) =>
{
if (grid.SelectedGridItem != null && grid.SelectedObject != null &&
grid.SelectedGridItem.PropertyDescriptor.CanResetValue(null))
menu.Items[0].Enabled = true;
else
menu.Items[0].Enabled = false;
};
grid.ContextMenuStrip = menu;
return form;
}
}
And decorate your collection property this way:
[Editor(typeof(MyCollectionEditor), typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Collection<MyElement> MyElements { get; private set; }
Following this approach you can simply add a separator, commands and description menus.