比如C# DataGridView 里有两列CheckBox 如何在CellContentClick事件中去判定其中一列的事件:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
      DataGridViewColumn column = this.dataGridView1.Columns[e.ColumnIndex];
      if(column is DataGridViewCheckBoxColumn)//所有CheckBox列
      {      }
}上面是所有列的CheckBox都包括进去了的。

解决方案 »

  1.   


    是向下面这样吗?int currentRowIndex = this.dataGridView1.CurrentRow.Index;//选中的当前行DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)this.dataGridView1.Rows[currentRowIndex].Cells["Column1"];//Column1列是CheckBox
    可是,比如我现在“Column1”和“Column2”两列都是CheckBox,用上面代码后,我在“Column2”列上的CheckBox点击,它也会响应事件的,而我现在只想它在“Column1”响应
      

  2.   

    private void DataGridView1_CellValueChanged(
         object sender, DataGridViewCellEventArgs e)
     {
         if (e.ColumnIndex == 0 &&
             DataGridView1.Columns[e.ColumnIndex].ValueType == typeof(bool))
         {}
    }