?
Solved

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

Posted on 2009-04-14
5
Medium Priority
?
974 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

752 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