|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
PropertyGrid, Custom UITypeEditorI 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 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 : Show quote > 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 |
|||||||||||||||||||||||