I have the following code which displays a dropdown list of selectable items in a propertygrid which generally works fine. However, the dropdown allows the items within the dropdown to be edited which causes an error on 'System.ComponentModel.EnumConverter.ConvertFrom' as its not a valid enum. For example, Option1
can be changed to OptionABC1
which I want to prevent.
There is a flag on PropertyStoreItem to set it to read only but this prevents the whole property being changed rather than preventing editing of the dropdown items.
How do I make the dropdown non-editable but still allow the fixed list to be selected? It might be a property on the propertygrid I need to change but cannot find it.
[Flags]
Public Enum SomePropertyTypes
{
Option1 = 1,
Option2 = 2,
Option3 = 4,
Option4 = 8,
Option5 = 16,
Option6 = 32
}
public partial class AddSomePropertyForm : RadForm
{
private RadPropertyStore store;
Public AddSomePropertyForm()
{
InitializeComponent();
this.store = this.CreatePropertyStore();
this.radPropertyGrid1.SelectedObject = store;
}
private RadPropertyStore CreatePropertyStore()
{
RadPropertyStore somePropertyStore = new RadPropertyStore();
PropertyStoreItem somePropertyType = new PropertyStoreItem(typeof(SomePropertyTypes), "PropertyName", SomePropertyTypes.Option1, "Property Info", "Group1", false);
somePropertyStore.Add(somePropertyType);
return somePropertyStore;
}
}
You should customize the drop down editor behavior by using the EditorInitialized event.
void radPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
{
PropertyGridDropDownListEditor editor = e.Editor as PropertyGridDropDownListEditor;
if (editor != null)
{
editor.DropDownStyle = RadDropDownStyle.DropDownList;
}
}
Here is an article on the matter: link