I assume then that this code is housed in a class and the collection you are editing is a collection of this class. In this case you should be able to add new instance of the class to the collection as no validation is done (or needed). However if the user attempts to change the element's MyEnum value to C then the error dialog will appear and the value will remain what it originally was.
public class MyClass { private Collection<YourClass> m_Coll = new Collection<YourClass>();
public Collection<YourClass> Items { get { return m_Coll; } } }
public class YourClass { private MyEnum myEnum;
public MyEnum MyEnum { get { return myEnum; } set { if (value == MyEnum.C) throw new ArgumentOutOfRangeException("value", "Dont use C");
myEnum = value; } } }
//In your form's load or somewhere propertyGrid1.SelectedObject = new MyClass();
Michael Taylor - 11/28/06
|