C# .Net 4.5 PropertyGrid: how to hide Properties

余生颓废 提交于 2019-12-01 04:17:41
Simon Mourier

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);
}

The easiest way to hide a property in PropertGrid and in a Custom Control for me is this:

public class Question
{
   ...

  [Browsable(false)]
  public int Element
  {
    get; set;
  }
}

Try BrowsableAttributes/BrowsableProperties and HiddenAttributes/HiddenProperties:

More info here

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