【发布时间】:2010-11-12 06:47:38
【问题描述】:
我认为必须有一个属性来隐藏数据网格视图中的公共属性。但我找不到它。
【问题讨论】:
-
您可以使用以下链接来满足您的要求:stackoverflow.com/questions/6960739/…
标签: c# attributes datasource
我认为必须有一个属性来隐藏数据网格视图中的公共属性。但我找不到它。
【问题讨论】:
标签: c# attributes datasource
如果您自己添加列...不要添加您不想要的列。
如果您启用了AutoCreateColumns,那么:
[Browsable(false)] 添加到您不想要的属性中.Visible 设置为false【讨论】:
PropertyDescriptor,再到PropertyInfo。不明显;p
AutoCreateColumns?
根据您的问题,我想您不想在 datagridview 中显示某些“列”?如果是这样,请使用 Columns 属性添加和删除在用于附加到网格的数据源上找到的任何自动创建的列。
默认情况下,DataGridView 将为基础数据源对象上的所有公共属性创建列。所以,
public class MyClass
{
private string _name;
public string Name
{
get{ return _name; }
set { _name = value; }
}
public string TestProperty
{
{ get { return "Sample"; }
}
}
...
[inside some form that contains your DataGridView class]
MyClass c = new MyClass();
// setting the data source will generate a column for "Name" and "TestProperty"
dataGridView1.DataSource = c;
// to remove specific columns from the DataGridView
// dataGridView1.Columns.Remove("TestProperty")
【讨论】: