views:

340

answers:

2

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.

A: 

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.

Jules
A: 

I think the behavior you describe in your own answer is not a bug and is by design, and frankly it's quite logical. Look the dropdown editors around: they offer the user to make a selection and therefore the result is a new value for the property (see ColorEditor, AnchorEditor, DockEditor, CursorEditor, ...). As such the property must not be readonly. A modal editor is more to edit a value (usually a reference type) and therefore can be used even if the property is readonly. Of course, this one can also be used to select a new value (like the FileNameEditor for example).

So maybe the answer is "look at your UI design". Are you sure you should use a dropdown editor to edit the content of a reference type?

Nicolas Cadilhac
Eh? What difference does it make how the various editors have been implemented in the framework? Modal and dropdown are styles. There's nothing in the documentation to say that a dropdown editor can't edit a ready only reference type. If I implement an editor, my decision on how to display it to the user is based on style and screen space, not on whether its a value or reference type.
Jules
This is your interpretation and I respect it at most. I am just saying "I think" this is Microsoft design to make it like this and as such if you want to make it work with the MS PropertyGrid then maybe you should review your own design. Don't expect such a fix from MS on the PropertyGrid.
Nicolas Cadilhac
In that case we're in agreement. I 100% expect microsoft to say it's by design - in which case it should be documented. I can easily pop-out my editor instead of dropping it down but it looks cooler as a drop down. At the moment i'm dropping it down with a modal button. No issues so far but we'll see ...
Jules