views:

1511

answers:

1

I'm trying to do some custom UI behavior on a Windows Forms PropertyGrid control. I'd like to be able to respond to clicks and double-clicks on the GridItems to change the state. For example, to flip a binary or ternary variable through its states.

I can get at the underlying view by looking up a child of typename "PropertyGridView" and can hook its Click event. Only problem is then what do I do? I can't find any functions that map mouse coordinates onto grid items.

There is a SelectedGridItem but this isn't helpful. There are many places you can click on a control that do not update this property, and so responding to a Click assuming SelectedGridItem is updated will get a lot of incorrect results.

Aside from purchasing a commercial property grid control or switching to a gridview of some kind, is there anything I can do here? The PropertyGrid is almost exactly what I need. I'm even considering wandering through with Reflector and doing some very unfriendly things with this control to get the data out that I need. :)

More info: I do know about using custom UITypeEditor classes, and am already doing this in other areas (color picker). Unfortunately doing custom UI work requires an extra click (to browse or drop-down some UI). For example, I have embedded a checkbox using UITypeEditor.PaintValue and would really like to be able to just click on it to check/uncheck.

+1  A: 

If you need to flip the values of a simple type you can have an enumeration value displayed in the property grid. This will appear automatically as a drop down list. If you need to create some more clever UI editor I suggest you'll take a look at the following articles that explain how to create custom UI in the property grid: http://msdn.microsoft.com/en-us/library/aa302334.aspx http://msdn.microsoft.com/en-us/library/aa302326.aspx

If you want to handle a value change in the property grid to do something in the application or change the values in the property grid you can handle the OnPropertyValueChanged that is raised after each change in the property grid.

Handling the mouse click and the mouse double click are not necessary once you can create your own UI editor. UI editors can be drop down editors or modal editors. Again, I strongly suggest you to read the above articles. They are quite good.

Yuval Peled
I'm trying to speed up the UI flow - the drop-down is one click too many. Here's a good example of what I mean. I've embedded a checkbox via UITypeEditor.PaintValue for bool properties. I'd like to check/uncheck by clicking in the checkbox. Double-clicking I want for advancing through simple enums.
Scott Bilas