1
votes

I am working in Microsoft Visual Studio Express 2013 with an SQL back end. I have a check-box column in a DataGridView and I am having a problem where when I change the check state of a check-box in the column the actual code doesn't run until I leave the cell. I tried using the dirty cell state change, but once I do that my code no longer recognizes e.rowindex or e.columnindex. Is there an event I can use that will run code as soon as the check-box is toggled and will still recognize the e.rowindex and e.columnindex code?

 Private Sub DGVCutList_CurrentCellChanged(sender As Object, e As EventArgs) Handles DGVCutList.CurrentCellChanged
    If e.RowIndex = -1 Then
            Exit Sub
        End If
end sub
1
@LarsTech This appears to be an article for c#, also, i know that cell dirty change is what I usually need. However, in this case its removing my ability to use "e." which is killing my code.Cheddar
c# or vb.net, the code reads the same.LarsTech

1 Answers

1
votes

There are a few different event's to use to accomplish this. The two events to use are: CurrentCellDirtyStateChanged and CellValueChanged. Please see code snippet below.

 'This will fire off after CurrentCellDirtyStateChanged occured...
 'You can get row or column index from e as well here...
 Private Sub DGVCutList_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DGVCutList.CellValueChanged
   'Do what you need to do...
 End Sub

 'This will fire immediately when you click in the cell...
 Private Sub DGVCutList_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles DGVCutList.CurrentCellDirtyStateChanged
  If DGVCutList.IsCurrentCellDirty Then
    DGVCutList.CommitEdit(DataGridViewDataErrorContexts.Commit)
  End If
 End Sub