是否有一个属性,我可以在我的课用它来告诉DataGridView的时候绑定到一个列表&LT不为它创建一个列; MyClass的> [英] Is there an Attribute I can use in my class to tell DataGridView not to create a column for it when bound to a List<MyClass>

查看:77
本文介绍了是否有一个属性,我可以在我的课用它来告诉DataGridView的时候绑定到一个列表&LT不为它创建一个列; MyClass的>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个类:

private class MyClass {
  [DisplayName("Foo/Bar")]
  public string FooBar { get; private set; }
  public string Baz { get; private set; }      
  public bool Enabled;
}

当我创建一个列表< MyClass的> 并将其分配给一个数据源 > DataGridView的,网格显示我的两列,美孚/酒吧和巴兹。这是我希望发生的。

When I create a List<MyClass> and assign it to the DataSource of a DataGridView, the grid shows me two columns, "Foo/Bar" and "Baz". This is what I want to happen.

目前,它的工作原理,因为启用是一个领域,不是一个属性 - DataGridView中只会抓取性能。然而,这是一个肮脏的黑客。

It currently works because Enabled is a field, not a property - DataGridView will only pick up properties. However, this is a dirty hack.

我想作一个启用物业太多,但仍然掩盖它在DataGridView。

I would like to make Enabled a property too, but still hide it on the DataGridView.

我知道我可以捆绑后手动删除列..但是这并不理想。

I know I can manually delete the column after binding.. but that's not ideal.

有一个属性相似的显示名称,那我可以标记的属性?类似 [可见(假)]

Is there an attribute similar to DisplayName, that I can tag a property with? Something like [Visible(false)] ?

推荐答案

<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx\"><$c$c>[Browsable(false)]将隐藏从的DataGridView属性

有一个可视化的设计通常显示在属性窗口中的
  成员要么没有可浏览的属性或标有
  BrowsableAttribute构造函数的可浏览参数设置为true。
  这些部件可以在设计时进行修改。会员打上
  BrowsableAttribute构造函数的可浏览参数设置为false是
  不恰当的设计时编辑,因此不
  在可视化设计器显示。默认值是true。

A visual designer typically displays in the Properties window those members that either have no browsable attribute or are marked with the BrowsableAttribute constructor's browsable parameter set to true. These members can be modified at design time. Members marked with the BrowsableAttribute constructor's browsable parameter set to false are not appropriate for design-time editing and therefore are not displayed in a visual designer. The default is true.

这篇关于是否有一个属性,我可以在我的课用它来告诉DataGridView的时候绑定到一个列表&LT不为它创建一个列; MyClass的&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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