dataGridView1中添加checkbox列,实现全选和反选:
//全选
private void CheckAll_CheckedChanged(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count>0)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells[0].Value = true;
}
}
}
//反选
private void CheckReverse_CheckedChanged(object sender, EventArgs e)
{
if (dataGridView1.Rows.Count>0)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue)
{
dataGridView1.Rows[i].Cells[0].Value = false;
}
else
dataGridView1.Rows[i].Cells[0].Value = true;
}
}
}