[Last Call] Learn how to a build a cloud-first strategyRegister Now

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
?
980 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 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

829 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