I'm working with the PropertyGrid control and using the SelectedObject property to display data within the PropertyGrid. Some of the properties in my grid are enum types. What I'd like to be able to do is hide some of the selections within the enum from the user. Take the below example: I would like to hide the enum of "Error" from the user. Is there a way to do this?

[TypeConverter(typeof(PropertySorter))]
public class Settings
{
    public enum FooType { Type1, Type2, Type3, Type4, Error };
    private FooType fakeProperty = FooType.Type1;

    public FooType FakeProperty
    {
        get { return fakeProperty; }
        set { // Do Something }
    }
}

And I am displaying the data in the PropertyGrid by calling:

myPropertyGrid.SelectedObject = mySettings;
有帮助吗?

解决方案

Visibility in PropertyGrid is usually controlled by [Browsable(...)]. So you could add [Browsable(false)] to your Error option. For example:

public enum Foo {
    A,
    [Browsable(false)] B
    C
}

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top