winform之datagridview中的datagridviewcheckboxcell中复选框如何通过代码来勾上或取消勾上?

2024-07-29 21:27:48
推荐回答(1个)
回答1:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((bool)dataGridView1.Rows[e.RowIndex].Cells[你的列下标].EditedFormattedValue == true)
      逗团胡      {
                dataGridView1.Rows[e.RowIndex].Cells[你的列下标].Value = false;
            }
            else
            {
                dataGridView1.Rows[e.RowIndex].Cells[你的列下标].Value = true;
            }
        }

 这个是单个的选中与取消代码


全选的与全取消的,准确说叫反选

for(int i=0;i{
  if ((bool)dataGridView1.Rows[i].Cells[你的列下标].EditedFormattedValue == true)
            {
                dataGridView1.Rows[i].Cells[你的列下标].Value = false;
            }
            else
            {
                dataGridView1.Rows[i].Cells[你的列下标].Value = true;
            }
}


全部选中

for(int i=0;i{
  if ((bool)dataGridView1.Rows[i].Cells[你的列下标].EditedFormattedValue == true)          
            {
                dataGridView1.Rows[i].Cells[你的列下标].Value = true;
            }
}

全部取消

for(int i=0;i{
  if ((bool)dataGridView1.Rows[i].Cells[你的列下标].EditedFormattedValue == true)          
            {
      山拦    或唤      dataGridView1.Rows[i].Cells[你的列下标].Value = false;
            }
}