Check/Uncheck a checkbox on datagridview

前端 未结 16 696
野性不改
野性不改 2020-11-30 11:19

Can someone help me why it doesn\'t work? I have a checkbox and if I click on it, this should uncheck all the checkbox inside the datagridview which were check

16条回答
  •  一生所求
    2020-11-30 11:30

    Simple code for you it will work

    private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (dgv.CurrentRow.Cells["ColumnNumber"].Value != null && (bool)dgv.CurrentRow.Cells["ColumnNumber"].Value)
        {
            dgv.CurrentRow.Cells["ColumnNumber"].Value = false;
            dgv.CurrentRow.Cells["ColumnNumber"].Value = null;
        }
        else if (dgv.CurrentRow.Cells["ColumnNumber"].Value == null )
        {
            dgv.CurrentRow.Cells["ColumnNumber"].Value = true;
        }
    }
    

提交回复
热议问题