Results 1 to 3 of 3

Thread: Problem with cell KeyDown event

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Question Problem with cell KeyDown event

    I have this code in the onKeyDown event of the datagridview.

    Code:
        Private Sub DataGridView1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
            Select Case e.KeyCode
                Case Keys.Return
                    e.SuppressKeyPress = True
                    SendKeys.Send("{TAB}")
            End Select
        End Sub
    This works. When the Enter button is pressed, it acts as the TAB button.

    The problem I am having is this only works if the datagridviewer is selected.
    As soon as I enter data into a cell (A cell is selected) the code wont work as it is not set for the cell keyDown event. The event does not exist, so I have to somehow create it.

    Does anyone know how to do this?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with cell KeyDown event

    Quote Originally Posted by tgf-47 View Post
    I have this code in the onKeyDown event of the datagridview.
    I'm a bit of a stickler for terminology so I will point out that there is no OnKeyDown event. There's an OnKeyDown method and a KeyDown event. Also, you can't have code in an event. The method that handles the event is not the event itself. So, to be precise, you have that code in the KeyDown event handler.

    As for the question, I've already answered it in another thread of yours. Please don't create multiple threads for the same question.

    http://www.vbforums.com/showthread.php?t=615909
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Problem with cell KeyDown event

    Please do not post multiple threads for the same question.

    This thread is now closed.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width