Search code examples
c#.netvb.netpropertygridcollectioneditor

Problem editing custom readonly collection in property grid, .net, winforms


I have a custom collection, lets says COL, that derives from ObjectModel.Collection.

I have my own collection editor that works fine when a property, of type COL, is Read and Write enabled. However, if I change the property to ReadOnly, the open editor button stops showing in the property grid.

As a test, I override my custom editor with the CollectionEditor, and that worked fine.

So, my question is, what check is the property grid making, that CollectionEditor passes but my collection editor fails?

There's not much to override in UITypeEditor, so I fear there's some hard coding going on with regards to CollectionEditor.

Cheers.

ETA:

I've answered the question below.


Solution

  • I've found out why it wasn't appearing and it appears to be a bug in the PropertyGrid. The button does appear if the EditStyle is set to Modal, but does not appear if it's set to DropDown.

    One would have thought that the styles were just for ..., well, style?

    Looking in reflector, the issue occurs because additional checks of readonly propertyies (such as checking if it's a reference type - and enabling the button) only happen if the style is set to modal. Hmmm, nice one.