jeudi 29 juin 2017

Windows Form DataGridView Checkbox value Always True When Checked/Unchecked

We have a Windows form application that has a DataGridView control containing a column with a checkbox in it.

enter image description here

When a user checks or unchecks the box in the row/cell in the DataGridView, we'd like to get the updated value (true or false).

The problem is, the value is always evaluated to true when using our current code implementation.

 private void gvDocumentContents_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.ColumnIndex == 6)
        {
            DataGridViewRow dgvr = gvDocumentContents.Rows[e.RowIndex];
            DataGridViewCheckBoxCell cbCell = dgvr.Cells[6] as DataGridViewCheckBoxCell;
            MessageBox.Show(cbCell.Value.ToString());
        }
    }

I've seen similar issues regarding this topic, however after spending the better part of the day looking, I haven't had much success with some of the other solutions that we tried.

Thanks




Aucun commentaire:

Enregistrer un commentaire