PropertyGrid, Custom UITypeEditor

R

Romain TAILLANDIER

Hi group

I have a simple property, of type string that can take only a few
defined value (as an enum).
The containing class can be viewed in a property grid, and i want the
user can select between the predefined values, exactly as it was an
enum.
I have created a specific UITypeEditor, the GetEditStyle method returns
a UITypeEditorEditStyle.DropDown, the EditValue create a ListBox
containing the predefined values. After the ListBox selected value
changed, the EditValue method returns the selected value of the list
box.

All work fine !

But if i don't click on the dropdown buton, i can edit the property
grid as if it was a string, and affect a not predefined value. How can
i prevent the property grid to be editable (of course i need the Set
accessor for this property) ?
How can i prevent the user to manually write a bad string ?

Thank
ROM
 
V

VisualHint

Hi Romain,

Assign a TypeConverter to your property. You can derive it from
StringConverter. Override GetStandardValuesExclusive() to return true.
You can avoid creating a new editor here (unless you really need it).
Simply use the TypeConverter to return the possible values in
GetStandardValues(). Hope this helps.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List -
http://www.propertygridresourcelist.com


Romain TAILLANDIER a écrit :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top