Link to home
Start Free TrialLog in
Avatar of garyinmiami2003
garyinmiami2003Flag for United States of America

asked on

Creating a Hot Key

I have a windows app converted from VS2003 to vs2005.  I would like to create a hotkey to make a selection in datagrid.  A hotkey to do anything will do and I will adapt to what I need.
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of garyinmiami2003



Well that does what I ask for in the question but let me ask another question or 2.  I have a grid in my windows app and when the focus is inside the grid, the event does not fire.  When I focus the control outside the grid to say a textbox, then the event fires when I press the key.
The 2nd question is syntax.  If I want to require the user to press 2 keys (say shift + enter) would it be
 If e.KeyCode = Keys.Shift + Keys.Enter Then....

I would like to provide the user with a hotkey to select a row from the grid rather than a (mouse double click etc)

I will award the points but a little more guidance would be a big help
>> 1st question
You have to capture the KeyDown event inside the datagrid. The same code that you use for the form KeyDown event you need to add to datagrid keydown event.

>> 2nd question
You can use this:
If e.Shift And e.KeyCode = Keys.F1 Then
            Debug.Print("F1 pressed ...")
End If

You also can use e.Control or e.Alt (if you need to change the hotkey)
I the case the message should be:

Debug.Print("SHIFT+F1 pressed ...")

Expert went beyond the actual question and provided additional example that I needed.
Glad I could help and thanks for the grade!