dataGridView 增加一列 DataGridViewCheckBoxColumn
然后设置复选框值如下图:
dataGridView增加两个事件
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e){//提交改变,触发dataGridView1_CellValueChanged事件,以便及时获取check的值改变事件if (dataGridView1.IsCurrentCellDirty)dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);}private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e){if (dataGridView1.SelectedCells.Count > 0){//获取选中行号int selectedIndex = dataGridView1.SelectedCells[0].RowIndex;//获取Checkbox改变的值,假如checkbox是在第2列var checkValue = dataGridView1.Rows[selectedIndex].Cells[1].Value;}}