Solved

How to Make ENTER Key Work Like the TAB key When the User Key Down?

Posted on 2009-04-14
5
962 Views
Last Modified: 2013-12-17
Good Day:

I am  using VS.NET 2005 with VB.NET to make a WinForms application.  I would like to make the Enter key=Tab key.  I am using the .NET DataGridView control and when the user key presses the Enter key; it creates a new row.  I would like to prevent this by making the Enter key act like the Tab key.  Unfortunately the code I tried does not work and when the user key presses the Enter key; it still creates a new row as follows:

 Private Sub GrdPODetail_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdPODetail.KeyDown


If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            SendKeys.Send("{TAB}")
        End If
 Any Suggestions?
Thank You,
Denise
0
Comment
Question by:DeniseGoodheart
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:djon2003
ID: 24140909
Could you try :

If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            e.Handled = True   ' <-- Change HERE
            SendKeys.Send("{TAB}")
        End If
0
 

Author Comment

by:DeniseGoodheart
ID: 24142453
Hello djon2003:

Thanks for your code but it did not work.  I key pressed ENTER and it went to the next row.
0
 
LVL 9

Expert Comment

by:djon2003
ID: 24146849
Ehm, I presume that the event that you subscribed to is too far from the real one. I mean here that using a datagridview and editing a cell makes a new Editing control to appear on top. Which, this one, is really modified.

So what you can do is :
-Within the event EditingControlShowing of your DGV add : AddHandler DGV.EditingControl.KeyDown, AddressOf EditKeyDown
-The new method EditKeyDown will have to code I posted you above. The enter key should then be catch at the good time.
Private Sub GrdPODetail_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdPODetail.EditingControlShowing 
AddHandler DGV.EditingControl.KeyDown, AddressOf EditKeyDown
End Sub
 
Private Sub EditKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Enter Then
            e.SuppressKeyPress = True
            e.Handled = True   ' <-- Change HERE
            SendKeys.Send("{TAB}")
        End If
End Sub

Open in new window

0
 

Author Comment

by:DeniseGoodheart
ID: 24150256
Hello djon2003:

Thanks for the additional code.  The following code gives me an error that reads:
Method 'Private Sub grdPODetail_EditingControlShowing(sender As Object, e As System.Windows.Forms.KeyEventArgs)' cannot handle Event 'Public Event EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs)' because they do not have the same signature.

Any Suggestions?
Thanks,
Denise
0
 
LVL 9

Accepted Solution

by:
djon2003 earned 500 total points
ID: 24156688
Oups I mistaken a little bit myself.. Just replace the GrdPODetail_EditingControlShowing sub parameters for the one needed.. so :
Private Sub GrdPODetail_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles grdPODetail.EditingControlShowing 
AddHandler DGV.EditingControl.KeyDown, AddressOf EditKeyDown
End Sub

Open in new window

0

Featured Post

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Retrieve Active Directory Groups a User belongs to in VB.NET 3 43
Groupbox Control ? 2 27
Regarding swagger API 1 32
PowerShell: ForEach-Object Export to CSV 4 34
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

763 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