>Update : to put it simply, when I'm in 0,0 my dgv goes to 1,1 i.o 0,1. When in 0,1 it goes to 1,0 which is what I want.
>
>
>Why after I press _Enter_ in my dgv (datagridview) does the currentcell goto the second column on the next row when I'm in the first column (which is not what I expect) and to the first column on the next row when I press _Enter_ in the second column which is what I expect. (btw the dgv has three columns, and lValidated is set by the cellvalidating even).
>
>
>
> Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
> If Me.lValidated Then
> Select Case e.ColumnIndex
> Case 0
> Me.DataGridView1.CurrentCell = Me.DataGridView1(1, e.RowIndex)
> Case 1
> Me.DataGridView1.CurrentCell = Me.DataGridView1(0, e.RowIndex + 1)
> End Select
> End If
> End Sub
>
>
>My debugging tells me that e.RowIndex = 0 when it leaves the cellendedit event, and I have not been able to detect when (if ?) the rowindex of the currentcell goes to 1 (this describes the situation when I press _enter_ in the leftmost upper cell)
I'd guess the problem is that you are not suppressing the default 'Enter' key behaviour. Can you get what you want by intercepting the Enter key instead. Something like:
Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
If DataGridView1.CurrentCell.ColumnIndex = 0 Then
DataGridView1.CurrentCell = DataGridView1(1, v.RowIndex)
Else
DataGridView1.CurrentCell = DataGridView1(0, v.RowIndex + 1)
End If
e.SuppressKeyPress = True
Return
End If
MyBase.OnKeyDown(e)
End Sub