Custom Editor for a Boolean Property in a PropertyGrid (C#)
-
I want to assign a custom editor to a boolean property in a PropertyGrid. I'm using the standard propertygrid (from namespace System.Windows.Forms). It is possible to assign custom editors to properties using the UITypeEditor class. However, as far as I can see, it is not possible to use it for a boolean property. I've tried to solve it by overriding the property grid so I can add items manually. I can add a string property that has a custom editor by the following piece of code: Properties.Item.Add("My Custom Editor", "", false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true); Properties.Item[Properties.Item.Count - 1].CustomEditor = new MyEditor(); So far so good, a custom editor appears (with a button in the grid). However, when I change the type to boolean by setting the default value on false (see below), the button to open the custom editor doesn't appear. Instead, a dropdown menu with true/false appears. Properties.Item.Add("My Custom Editor", false, false, "Properties with custom UITypeEditor", "The component accept custom UITypeEditor.", true); Properties.Item[Properties.Item.Count - 1].CustomEditor = new MyEditor(); Does anyone has a solution for this? Thanks in forward! Regards, Peter
-
Answer:
The Microsoft PropertyGrid checks this flag to determine if it displays a dropdown arrow (flag == true) or a modal button (flag == false): bool flag = gridEntryFromRow.NeedsDropDownButton | gridEntryFromRow.Enumerable; The first part is true if the UITypeEditor style is DropDown and the second part is true if the attached TypeConverter's GetStandardValuesSupported returns true. You can check all this in PropertyGridView.SelectRow in Reflector. If you are able to attach a custom TypeConverter to your boolean (I would derive it from BooleanConverter) whose GetStandardValuesSupported method is overriden to return false, then you will get your modal button. Of course you loose the standard values (double clicking won't cycle the values for example), this is a tradeoff. I have identified this issue a long time ago and that's why in my own PropertyGrid I am not so strict and will enable a modal editor even if standard values are defined as long as I attach a ForceEditor attribute to the property.
Peter van Kekem at Stack Overflow Visit the source
Related Q & A:
- How do I use a custom avatar like a picture of me?Best solution by Yahoo! Answers
- What degree is needed to be an editor for a magazine?Best solution by Yahoo! Answers
- What's a best custom firmware on a PSP?Best solution by Yahoo! Answers
- What program is a quick free video editor for cutting a long video into a size for YouTube (9 minutes?Best solution by Yahoo! Answers
- What is a Characteristic Property?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.