I want to move the cursor from column 1 to column 4 but what happened instead the cursor moves to column 5, this happens when I use the enter key event. but run well if I double click.
The following description of the program:
there are 7 columns of code, item description, unit, price, qty, discount, item amount
code when key enter press :
vb.net Code:
  1. Private Sub dg_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dg.KeyUp
  2.         If e.KeyData = Keys.Enter Then
  3.             Dim cRow As Integer = dg.CurrentCell.RowIndex
  4.             Dim cCol As Integer = dg.CurrentCell.ColumnIndex
  5.  
  6.             Select Case cCol
  7.                 Case 0, 1, 2
  8.                     LoadProduct()
  9.                     MoveCell(cRow, 4)
  10.         end select
  11.     end if
  12. end sub

and code when double click at datagridview.
vb.net Code:
  1. Private Sub dg_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellDoubleClick
  2.         Select Case e.ColumnIndex
  3.             Case 0, 1
  4.                 LoadProduct()
  5.                 MoveCell(cRow, 4)
  6.         End Select
  7. End Sub
at LoadProduct() method program load form dialog to get product list and then choose one of them.

vb.net Code:
  1. 'move cursor to crow & ccol cell
  2.  Sub MoveCell(ByVal crow As Integer, ByVal cCol As Integer)
  3.         If crow <= 0 Then crow = 0
  4.         dg.CurrentCell.Selected = False
  5.  
  6.         dg.Rows(crow).Cells(cCol).Selected = True
  7.         dg.CurrentCell = dg.SelectedCells(0)
  8.         dg.Refresh()
  9.  
  10.     End Sub

I have some ways but still could.

thank you