我在C#中的小的應用程序,它有一個被使用填充一個DataGridView:如何在使用自定義DataSource時隱藏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;
}
}
}
一切工作正常,並且DataGridView被填充正確的數據,但現在我想隱藏column2。我試圖在列聲明上面添加[Browsable(false)]
,這會隱藏它,但我也需要從代碼訪問列值,並且當我使用[Browsable(false)]
並嘗試讀取內容時,它的行爲就像列不存在一樣。如果我不使用它,我可以毫無問題地閱讀該列,但它在DataGridView中可見。
我怎麼能隱藏列,但仍然能夠從代碼中讀取其內容?
'Visible'在創建控件後是「ReadOnly」。 –