日期:2014-05-20  浏览次数:21138 次

C#中如何隐藏DATAGRID指定的列
string   mysql;
if(this.cbxSaiShi.Text== "*** ")
{
mysql= "select   distinct   字段1,日期,字段5,字段9   from   footballdata ";

}
else
{
mysql= "select   distinct   字段1,日期,字段5,字段9   from   footballdata   where   字段1= ' "+this.cbxSaiShi.Text+ " ' ";
}
MessageBox.Show(mysql);
OleDbConnection   con=DBCONN.DBCONNECTION();
con.Open();
OleDbDataAdapter   myAdapter   =   new   OleDbDataAdapter(mysql,   con);
DataTable   myTable   =   new   DataTable();
myAdapter.Fill(myTable);
this.dgdTotal.DataSource   =   myTable;

我在DATAGRID中显示上面代码中的字段,现在想增加一个botton隐藏字段5,代码该怎么写呀,谢谢。

------解决方案--------------------
1。自定义datagrid的样式。
2。直接从sql语句处理。
------解决方案--------------------
visble
------解决方案--------------------
自定义datagrid的样式 将列宽设0
------解决方案--------------------
解决办法:

foreach(DataGridTableStyle dgt in myDataGrid.TableStyles)
{
dgt.GridColumnStyles[列索引].Width=0;
}

不过,给你个建议:net2.0都推出这么长时间,为什么还用DATAGRID,DataGridView功能强大多了,一行代码就搞定:
dataGridView1.Columns[5].Visible = false;