Check/Uncheck a checkbox on datagridview

前端 未结 16 735
野性不改
野性不改 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:50

    The code bellow allows the user to un-/check the checkboxes in the DataGridView, if the Cells are created in code

    private void gvData_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)gvData.Rows[e.RowIndex].Cells[0];
    
        if (chk.Value == chk.TrueValue)
        {
            gvData.Rows[e.RowIndex].Cells[0].Value = chk.FalseValue;
        }
        else
        {
            gvData.Rows[e.RowIndex].Cells[0].Value = chk.TrueValue;
        }
    
    }
    

提交回复
热议问题