Vb.net 2008 Datagridview press Enter key

i have 2 datagridview i need some sample code for When user press Enter Key it will jump from Datagridview1 to Datagridview2.
aaronthamAsked:
Who is Participating?
 
jppintoConnect With a Mentor Commented:
Try the code below.

jppinto
Private Sub DataGridView1_Keydown (...) Handlers DataGridView1.KeyDoWno
   If e.KeyCode = Keys.Enter Then
       DataGridView2.Focus()
       e.SuppessKeyPress = True
  End If 
End Sub

Open in new window

0
 
aaronthamAuthor Commented:
Currently, pressing the enter key it moves to the next row in the
grid, but I want to use the enter key to select a row but because it
currently moves to the next row I'm having trouble getting the correct
row
0
 
CodeCruiserCommented:
Does the given code solve your problem? You original question and this question does not match!
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
You have to override the ProcessCmdKey and check if the cell is in edit mode and jump to the next datagridview. That's the only way to get that.
Example:

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
 
        If keyData = Keys.Enter AndAlso Me.DataGridView1.IsCurrentCellInEditMode Then
            DataGridView2.Focus()
            Return True
        Else
            Return MyBase.ProcessCmdKey(msg, keyData)
        End If
 
    End Function

Open in new window

0
 
aaronthamAuthor Commented:
hi jpaulino,
i try your code don't work. anyway maybe i don't know how to use funtion.
can provide code how to use this funtion
0
 
Jorge PaulinoIT Pro/DeveloperCommented:

just place the code I have showed you in the top of the form (after the Public Class Form1) and change the datagridview names for the correct names (if necessary)

If still dont work, show how do you have.
0
 
aaronthamAuthor Commented:
hi jpaulino,

now i have Datagridview3 and Datagridview4, how to jump from Datagridview2 to Datagridview3 and from Datagridview3 to Datagridview4
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
You just need to extend the If condition with some extra elseif's
Try this way:

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
 
        If keyData = Keys.Enter AndAlso Me.DataGridView1.IsCurrentCellInEditMode Then
            DataGridView2.Focus()
            Return True
        ElseIf keyData = Keys.Enter AndAlso Me.DataGridView2.IsCurrentCellInEditMode Then
            DataGridView3.Focus()
            Return True
        ElseIf keyData = Keys.Enter AndAlso Me.DataGridView3.IsCurrentCellInEditMode Then
            DataGridView4.Focus()
            Return True
        Else
            Return MyBase.ProcessCmdKey(msg, keyData)
        End If
 
    End Function

Open in new window

0
 
aaronthamAuthor Commented:
Thank You
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.