I have a datagridview. I want to validate the row before letting the user do anything else (pressing a button off the grid). I figured out how to do this. I would like to prevent them from switching rows if the validation does not work. I try to set the current cell to the cell that I am on in rowvalidation, but this does not work. I can't use the e.cancel property in rowvalidate because if you press a button, it will cancel, but the focus does not go back to the grid, and you can press the button a second time. (If that does not make sense, I am just trying to say e.cancel in rowvalidate does not work.
Private Sub DataGridView1_RowValidatin
g(ByVal sender As Object, ByVal e As System.Windows.Forms.DataG
ridViewCel
lCancelEve
ntArgs) Handles DataGridView1.RowValidatin
g
If Len(DataGridView1.Item(Dat
aGridView1
.CurrentCe
ll.ColumnI
ndex, DataGridView1.CurrentCell.
RowIndex).
Value) < 4 Then
MsgBox("fail")
Me.DataGridView1.Focus()
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cell
s(0)
rowDirty = True
Else
rowDirty = False
End If
End Sub
Start Free Trial