Help with Controling ENTER KEY inside a DataGrid

Posted on 2005-04-13
Last Modified: 2010-04-23
I have a datagrid that shows a list of customers.  Currently I have some code in the double click event of the data grid that fires when they double click on the row header.  I first would like to be able to use my arrow keys to move up and down on the grid to the row the user wants.  This already works except it only highlights the cell they are in.. I would like for it to keep the whole row highlghted at all times.  This grid is never used for updating.. its read only.  Ones the user is on the row they want, i would like them to be able to hit the ENTER KEY that would basicly fire the same code as the DOUBLE CLICK EVENT does?

Any suggestions on this?

Question by:accmats
    LVL 25

    Expert Comment

    use the currenccellchange event


     Private Sub dg_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

        End Sub

    Author Comment

    ok... that worked to highlight the rows as I use the down arrow to get to the need row.  Now how can I capture the ENTER KEY and make it do basicly the same code I currently have the DOUBLE CLICK event doing?
    LVL 25

    Accepted Solution

    Hi accmats, well that is a bit more difficult, you have to create your own datagrid (and use that datagrid) and override the ProcessCmdKey, like

    Public Class MyDataGrid
              Inherits DataGrid

              Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean
                   If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
                        Return True
                   End If
                   Return MyBase.ProcessCmdKey(msg, keyData)
              End Function 'ProcessCmdKey

         End Class

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now