Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a .NET program that captures the up and down arrow keys to move through a SQL database. The code has been working as intended since I entered, Recently I had a problem that required removing and reinstalling Windows 10 and since then the up and down arrows don't work through the database. I am running Visual Studio and Windows 10 and my code is:

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown

    Select Case e.KeyCode
        Case Keys.Up
            DVD_ListBindingSource.MovePrevious()
            e.Handled = True
        Case Keys.Down
            DVD_ListBindingSource.MoveNext()
            e.Handled = True
    End Select
End Sub

Not sure where to go from here

What I have tried:

Because the code has been working previously I have no idea where to start. I'm not sure if there is a registry item that needs to be switched on or off, or if I need to adjust my code.
Posted
Updated 17-May-19 9:12am

1 solution

If the form is handling the key events, the form is also going to have to have KeyPreview = True for the form event handlers to get first crack at the key events. Otherwise, the key events will go straight to the control that has the focus, not to the form.
 
Share this answer
 
Comments
Member 10376725 17-May-19 15:41pm    
Dave, this program has been evolving for about 6 years and I've never had to use that before. Doesn't mean I shouldn't have, I just haven'y. I'm not sure where to put it, I tried it in the subroutine, and then in the declarations and neither changed anything. This re-install has caused a number of problems, the first being I couldn't publish a program and every time I tried it wanted to install .NET Framework 4.7.2. Finally got it to publish but still wants to install the Framework. But this has really got me flustered.
Dave Kreskowiak 17-May-19 16:00pm    
I'm just telling you how the key events work. Without KeyPreview turned on, if the form has the focus, then those events will work. If one of the controls, like the datagrid or a button or whatever control on the form has the focus, then they won't.

You can just turn on KeyPreview just by clicking on the form in the designer and finding the KeyPreview item in the Properties window.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900