我在c#中有一个小应用程序,它有一个使用以下内容填充的DataGridView:
grid.DataSource = MyDatasource array;
MyClass保存列的结构,它看起来像这样:
class MyDatasource
{
private string column1;
private string column2;
public MyDatasource(string arg1, string arg2)
{
this.column1 = arg1;
this.column2 = arg2;
}
public string column1
{
get
{
return this.column1;
}
set
{
this.column1 = value;
}
}
public string column2
{
get
{
return this.column2;
}
set
{
this.column1 = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,DataGridView会填充正确的数据,但现在我想隐藏column2.我尝试[Browsable(false)]
在列声明之上添加,这将隐藏它,但我还需要从代码中访问列值,当我使用[Browsable(false)]
并尝试读取内容时,它就像列不存在一样.如果我不使用它,我可以毫无问题地阅读该列,但它在DataGridView中可见.
我怎么能隐藏列但仍能从代码中读取其内容?