以编程方式隐藏PropertyGrid中的字段 [英] Programmatically Hide Field in PropertyGrid

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

问题描述

使用

<System.ComponentModel.TypeConverter(GetType(System.ComponentModel.ExpandableObjectConverter))> _

在一个由数字组成的类(它是另一个类的属性)的声明上属性。

on the declaration of a class (which is a property of another class) that consists of a number properties.

我只用...加载此类的实例...

I load an instance of this class with simply ...

PropertyGrid1.SelectedObject = oColumn

很显然,我不想手动在代码中构建propertygrid ,我知道该怎么做。

Obviously I don't want to manually build the propertygrid in code, I know how to do that.

但这是问题所在。根据属性的值,某些其他属性应该不可见,就好像我使用

But here's the problem. Depending on the value of a property, certain other properties should not be visible, as though I'd used the

<System.ComponentModel.Browsable(False)> _

属性声明中的属性。

是否可以通过编程方式执行此操作,而无需手动处理属性网格的所有构建>

Is there anyway to do this programmatically, without having to handle all the building of the property grid manually>

推荐答案

希望然后找到gridItem.Hide(),答案是否定的。在MS PropertyGrid中实现此目标的唯一方法是通过TypeConverter或自定义类型描述符(实现ICustomTypeDescriptor)的GetProperties方法动态发布属性。我会首先尝试使用TypeConverter(特别是如果您要检查的属性值处于同一级别),那么要做的编码就更少了。

if you were hoping for a gridItem.Hide() then, the answer is no. The only way to achieve that in the MS PropertyGrid is to dynamically publish your properties through the GetProperties method of a TypeConverter or custom type descriptor (that implements ICustomTypeDescriptor). I would try first with the TypeConverter (expecially if the property values you want to check are at the same level), there is less coding to do.

这篇关于以编程方式隐藏PropertyGrid中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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