我认为必须有一个属性来隐藏datagridview中的公共属性。但我找不到它。
答案 0 :(得分:63)
如果您自己添加列...请不要添加您不想要的列。
如果您启用了AutoCreateColumns
,那么:
[Browsable(false)]
添加到您不想要的属性.Visible
设置为false 答案 1 :(得分:3)
答案 2 :(得分:0)
从你的问题,我想你不想在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")