Solved

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

Posted on 2009-04-14
5
951 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Vb.Net Menu 1 21
Convert string to date 3 39
.Net Web Site Password specs 2 19
Copy/Clone an object. 9 10
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now