C#.NET 4.5的PropertyGrid:如何隐藏属性 [英] C# .Net 4.5 PropertyGrid: how to hide Properties
问题描述
这个问题很简单(我希望这有一个简单的解决方案!):我想隐藏(可浏览(假))属性元素(在我的PropertyGrid对象)时,它的零
公共类问题
{
...
公众诠释元
{
得到;组;
}
}
你可以做的是重用我的答案描述在这里这个问题上,这样 DynamicTypeDescriptor
类: <一href="http://stackoverflow.com/questions/16422844/propertygrid-browsable-not-found-for-entity-framework-created-property-how-to-f">PropertyGrid可浏览找不到实体框架创建属性,怎么找呢?
这样的,例如:
公共Form1中()
{
的InitializeComponent();
DynamicTypeDescriptor DT =新DynamicTypeDescriptor(typeof运算(问题));
问Q =新的问题(); //初始化问题,你所希望的方式
如果(q.Element == 0)
{
dt.RemoveProperty(元素);
}
propertyGrid1.SelectedObject = dt.FromComponent(q)的;
}
The problem is simple(and I hope that this have a simple solution!): I want to hide ( Browsable(false) ) the property "Element" (in my PropertyGrid object) when it's zero.
public class Question
{
...
public int Element
{
get; set;
}
}
What you could do is reuse the DynamicTypeDescriptor
class described in my answer to this question here on SO: PropertyGrid Browsable not found for entity framework created property, how to find it?
like this for example:
public Form1()
{
InitializeComponent();
DynamicTypeDescriptor dt = new DynamicTypeDescriptor(typeof(Question));
Question q = new Question(); // initialize question the way you want
if (q.Element == 0)
{
dt.RemoveProperty("Element");
}
propertyGrid1.SelectedObject = dt.FromComponent(q);
}
这篇关于C#.NET 4.5的PropertyGrid:如何隐藏属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!