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

白昼怎懂夜的黑 提交于 2019-12-20 02:41:31

问题


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;

回答1:


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
}



来源:https://stackoverflow.com/questions/16652461/is-it-possible-to-hide-an-enum-value-from-a-propertygrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!