首页 > 代码库 > 将DataGridView每一行的复选框选中,将DataGridView选中的复选框删除

将DataGridView每一行的复选框选中,将DataGridView选中的复选框删除

1,将DataGridView每一行的复选框选中

//DataGridView的行大于0行

if (dgv_MessageList.Rows.Count > 0)
            {
                for (int i = 0; i < dgv_MessageList.Rows.Count; i++) //循环DataGridView每一行
                {
                    if (checkBox1.Checked)  //如果选中将每一条都选中
                        dgv_MessageList.Rows[i].Cells["checkbox"].Value = http://www.mamicode.com/true;
                    else
                        dgv_MessageList.Rows[i].Cells["checkbox"].Value = http://www.mamicode.com/false;
                }
            }

 

2,将DataGridView选中的复选框删除

if (dgv_MessageList.Rows.Count > 0)
            {
                for (int i = 0; i < dgv_MessageList.Rows.Count; i++)
                {
                    if (dgv_MessageList.Rows[i].Cells["checkbox"].Value =http://www.mamicode.com/= null)
                        continue;
                    if ((bool) dgv_MessageList.Rows[i].Cells["checkbox"].Value) //如果check已经选中
                    {

          //调用删除的方法

       }

      }
             }