WinForm如何让datagridview中CheckBox被选中时候触发事件?

如题:当datagridview中CheckBox被选中时候就调用某个方法?
2023-12-17 23:31:21
推荐回答(4个)
回答1:

我觉得比较好的方式是用datagridview 控件的cellcontentclick事件 例如:
如果嵌入的 DataGridViewCheckBoxCell 列在第一列,判断状态并添加处理事件可以为:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

if (e.ColumnIndex == 0 && e .RowIndex != -1)

{

//获取控件的值

MessageBox.Show(this.dataGridView1.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString());

//或者可以做其他事件处理程序

}

}

回答2:

在datagridview中的事件中选取一个我记得是DataBinding事件,然后你遍历你选中的那个checkbox选项,然后根据ID调用方法

回答3:

this.dgvDoctor.Rows[i].Cells["check"].EditedFormattedValue.ToString()获得checkBox是否被选中,在datagridview的CellContentClick事件中判断,如果选中,则调用

回答4:

那加上datagridview单机单元格的事件啊,事件中判断当前是不是checkbox,是的话,就执行某个方法