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

1

4

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;
Wrigley answered 20/5, 2013 at 15:4 Comment(0)
Q
11

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

Quotation answered 20/5, 2013 at 15:15 Comment(1)
This was so much more simple than I thought it would be. Thanks Marc!Wrigley

© 2022 - 2024 — McMap. All rights reserved.