1、如何隐藏一列,但是要把列头显示出来,我直接用dataGridView1.Columns[2].Visable = false;结果连列标题都没有了。 2、有一列是下拉列表,我想让它在没有点击的情况下是不显示的,只有当用鼠标点击这个单元格的时候才显示出来,那么怎么隐藏一个像这种单元格呢?

解决方案 »

  1.   

    1.
    for(int i=0;i<dataGridView1.Rows.Count;i++)
    {
        dataGridView1.Rows[i][2].Visable=false;
    }2.
    这个需要触发的是datagridview的CellContentClick事件,在这个事件里,判断你的datagridview的ColumnIndex是不是所属的combobox的索引,如果是,才进行进一步的操作,例如:
    //假定你的
    combobox的索引是5,如果不确定,可以通过弹出e.ColumnIndex看看你所点击的combobox的索引是几private void datagridview_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                if (e.ColumnIndex == 5 && e.RowIndex != -1 && !datagridview.Rows[e.RowIndex].IsNewRow)
                {
                    //这个地方写你的事件操作,例:
                      String id = datagridview.Rows[e.RowIndex].Cells[0].Value.ToString();
                   //......
                }
    }
      

  2.   

    设置控件的  Visable为false 
    点击这个单元格的事件里 CellContentClick  里面把控件Visable设为true
      

  3.   

       这个地方dataGridView.Rows[i][2].Visable = false;这句话不对啊,VS2010提示出错了,Rows[i]不可以再有个[2]了
      

  4.   

    改成dataGridView1.Rows[i].Cells[2].Visable,写习惯了,手误。。
      

  5.   

    dataGridView1.Rows[i].Cells[2].value的值设为null就行了,单击时再给赋值