在DGV中更改复选框的最佳事件



我在Microsoft Visual Studio Express 2013与SQL后端工作。我在DataGridView中有一个复选框列,我遇到了一个问题,当我更改列中复选框的复选状态时,实际代码不会运行,直到我离开单元格。我尝试使用脏单元格状态更改,但是一旦我这样做,我的代码就不再识别e.rowindex或e.rowindex。是否有一个事件,我可以使用它来运行代码,只要复选框被切换,仍然会识别e.o rowindex和e.o columnindex代码?

 Private Sub DGVCutList_CurrentCellChanged(sender As Object, e As EventArgs) Handles DGVCutList.CurrentCellChanged
    If e.RowIndex = -1 Then
            Exit Sub
        End If
end sub

可以使用几个不同的事件来完成此操作。使用的两个事件是:CurrentCellDirtyStateChangedCellValueChanged。请参阅下面的代码片段。

 '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

最新更新