In VB.NET 2005 what is the best way to get control when someone checks or unchecks a checkbox cell in a datagridview.

I am getting conflicting results and it seems that either the current cell is the previous cell or the value is always false.

I just want a way that when someone checks or unchecks the cell I get control of the current cell and it has the checked value. Either the new value or the old as long as it is consistant.


7 Years
Discussion Span
Last Post by TomW

I have tried CellClick but it doesn't work.

The checkbox cell

is ALWAYS nothing. When or when it is not checked.

The idea is to do something when it is check just as if it was a normal checkbox.

Even when the I hard code the column (0 in my case).


Hello QBD, I understand your problem; unfortunately there is no easy solution. What you have to understand is like working directly in your database, any value changes you make to a cell dont truly take effect in that cell/record until you move to another record/row; at which time the new value is then validated and changes commited.

So even though the CellClick event may actuall fire each time its clicked (unlike most of the other events) its still not seeing that new value until you move to the next row.

The best that you can manage is checking that value when it does move to the next row in a consistent manner. The below event & sample triggers when you move to the next row, but will give you the changed value from the row you just left.

Private Sub dgv_CellValueChanged(...) Handles dgv.CellValueChanged

    Dim sbMsg As New StringBuilder

     With sbMsg
        .AppendLine(String.Format("Row Index: {0}", e.RowIndex))
        .AppendLine(String.Format("Column Index: {0}", e.ColumnIndex))
        .AppendLine(String.Format("Column Name: {0}", dgv.Columns(e.ColumnIndex).Name))
        .AppendFormat("Value: {0}", dgv.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
    End With

End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.