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

时间:2021-08-14 09:46:33

 (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;
                }
            }