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.   

    1。自定义datagrid的样式。
    2。直接从sql语句处理。
      

  2.   

    自定义datagrid的样式  将列宽设0
      

  3.   

    解决办法:    foreach(DataGridTableStyle dgt in myDataGrid.TableStyles)
        {
            dgt.GridColumnStyles[列索引].Width=0;
        }不过,给你个建议:net2.0都推出这么长时间,为什么还用DATAGRID,DataGridView功能强大多了,一行代码就搞定:
       dataGridView1.Columns[5].Visible = false;
      

  4.   

    foreach(DataGridTableStyle dgt in myDataGrid.TableStyles)
        {
            dgt.GridColumnStyles[列索引].Width=0;
        }myDataGrid.TableStyles.Count 怎么提取的值是0呀,这样的话循环就有啦