winfrom_DataGridView_点击任何单元格_自动勾选和取消第一列的checkbox
程序员文章站
2022-04-05 15:13:58
...
private void dgvClass_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1) return;
if (e.ColumnIndex > 0)
{
if (dgvClass.Rows[e.RowIndex].Cells[0].Value == null)
{
dgvClass.Rows[e.RowIndex].Cells[0].Value = true;
}
else
{
dgvClass.Rows[e.RowIndex].Cells[0].Value = !(bool)dgvClass.Rows[e.RowIndex].Cells[0].Value;
}
}
}