Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-14
5
Medium Priority
?
977 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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 …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 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