(datagridview)如果单击checkbox,全选.(第一列为复选框) (如图)

时间:2021-12-13 08:50:13

 (datagridview)如果单击checkbox,全选.(第一列为复选框) (如图)

选中左上角的复选框则下面的全选中..取消则全非选中:

 //全选、全不选功能
            if (cb.Checked == true)
            {
                for (int i = 0; i < dGV.RowCount; i++)
                {
                    dGV.Rows[i].Cells[0].Value = true;
                }
            }
            else if (cb.Checked == false)
            {
                for (int i = 0; i < dGV.RowCount; i++)
                {
                    dGV.Rows[i].Cells[0].Value = false;
                }
            }