Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to hide an enum value from a PropertyGrid?

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;
like image 517
Michael Mankus Avatar asked Jan 13 '23 08:01

Michael Mankus


1 Answers

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

like image 183
Marc Gravell Avatar answered Jan 16 '23 18:01

Marc Gravell