Link to home
Start Free TrialLog in
Avatar of b001
b001Flag for Afghanistan

asked on

Datagridview move cursor to right

Hi
I am trying to move the cursor to right in the grid when ENTER key is pressed.
My Code
 
Private Sub DataGridParts_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridParts.KeyDown

        If e.KeyCode = Keys.Enter Then
         
                e.SuppressKeyPress = True
                Dim iCol = DataGridParts.CurrentCell.ColumnIndex
                Dim iRow = DataGridParts.CurrentCell.RowIndex
            If iCol = 9 Then
                        DataGridParts.CurrentCell = DataGridParts(0, iRow + 1)
                    Else
                        DataGridParts.CurrentCell = DataGridParts(iCol+1, iRow)
              End If
       
     end if
end sub
It works fine as long as you don not change any cell value.
If I change the cell text and then when ENTER key pressed it goes down to next row instead going to right in the sale row.

Please help
Avatar of louisfr
louisfr

Use the PreviewKeyDown event to tell the control Enter must be processed as an input key:
private void DataGridParts_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    switch (e.KeyCode)
    {
        case Keys.Enter:
            e.IsInputKey = true;
            break;
    }
}

Open in new window

Avatar of b001

ASKER

Hi losisfr

please convert the above code for  VB Basic
Thanks
Avatar of b001

ASKER

I mean Visual Studio Basic
ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial