是否可以隐藏PropertyGrid中的枚举值? [英] Is it possible to hide an enum value from a PropertyGrid?

查看:277
本文介绍了是否可以隐藏PropertyGrid中的枚举值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PropertyGrid 控件并使用 SelectedObject 属性来显示<$ c中的数据$ C> 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;


推荐答案

PropertyGrid 通常由 [Browsable(...)] 控制。因此,您可以将 [Browsable(false)] 添加到错误选项。例如:

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
}

这篇关于是否可以隐藏PropertyGrid中的枚举值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆