?
Solved

Vb.net 2008 Datagridview press Enter key

Posted on 2009-04-20
9
Medium Priority
?
1,273 Views
Last Modified: 2013-11-26
i have 2 datagridview i need some sample code for When user press Enter Key it will jump from Datagridview1 to Datagridview2.
0
Comment
Question by:aarontham
9 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 1000 total points
ID: 24188471
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
 

Author Comment

by:aarontham
ID: 24191063
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24192332
Does the given code solve your problem? You original question and this question does not match!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 1000 total points
ID: 24192386
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
 

Author Comment

by:aarontham
ID: 24192509
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 24192548

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
 

Author Comment

by:aarontham
ID: 24201253
hi jpaulino,

now i have Datagridview3 and Datagridview4, how to jump from Datagridview2 to Datagridview3 and from Datagridview3 to Datagridview4
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24201757
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
 

Author Comment

by:aarontham
ID: 24211663
Thank You
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question