Adding custom drop-down, resizable controls to PropertyGrid

This article shows you how to implement custom controls in your PropertyGrid that can handle any property object type…

This was one of those where I kept revisiting it time after time to little avail. Hours of searching and article reading led to many dead ends and frustrated hours, until I found the answer. Like most coding nightmares, it was 5 simple lines put in exactly the right place! These lines:

Step 1: Create a new UITypeEditor

This interfaces the property to the custom editor. value contains the value passed from the property. It can be of any object type. You can therefore pass this to your custom control to inform any editing functions therein.

Create a new class:

Step 2: Create your custom editor:

In this example, I have just used a custom class that inherits TextBox . However, you can use any controls, even a custom  UserControl .

Note m_EditorService.CloseDropDown . Put this wherever you want the dropdown to close itself (e.g. after a value selection).

Step 3: Tell your class property to use the custom editor:

And that’s it! These are the basics of this approach, but you can build highly customised PropertyGrid editors through this approach. An example of what can be achieved, below:

 

About stigzler 33 Articles
Chief crook and wattle bosher.

Be the first to comment

Leave a Reply

Your email address will not be published.


*