[RESOLVED] how to bridge special key press from datagrid to form (resolved)
Dear all,
i have a form, i want to give it some hot keys functionality, so i did the following :
1 - i set the keypreview of the form to true
2 - in the keyup event i set a select case based on the e.keycode , like this
VB Code:
select case e.keycode
case 112
'save code
case 113
'delete code
case 114
'add new code
end select
it works fine, but !!!!!
when i have a datagrid on the form, and the focus is on the grid none of these hotkeys triggers anything.
when i move the focus to any other control on the form , the hot keys works well. i think the datagrid blocks the key strokes inside it assuming that i am editing inside its cells.
what i need now is to alter the keyup event on the datagrid and check if any of the keys i want (hot keys) is pressed , then i want to send the same keys to the form itself.
i don't want to activite my subs directly from the grid, i just want to bridge the keys from the grid to the form, and let the form handle it.
why want i do that in specific, because this is the base form of a project and during inheriting i may have different forms responding deifferently from each other.
Can i pass some special keys from the grid to the form (F1, F2 etc...), and How ????
thx in advance
RGDS
Re: how to bridge special key press from datagrid to form
Maybe adding an event handler to the datagrid using 'Addhandler' and addressing the form's keyup event would help.
For help regarding the 'Addhandler' statement, visit http://msdn.microsoft.com/library/de...rstatement.asp .
I hope this helps :)
Peace! :wave:
Re: how to bridge special key press from datagrid to form
i have tried linking both the datagrid and the form keyup events to the same handler without no hope.
while i was trying i figured that the datagrid doesn't feel anything when typing within it's cells. even when i wrote i single line inside the ky up event like
it didn't execute, only when the datagrid was empty with no cells at all, it felts the key up event. i want to trigger the key up event while editing inside each cell
how can i do this, or how can i make the datagrid cell echos the keyup events to the form for processing.
thx for your time
Re: how to bridge special key press from datagrid to form
Re: how to bridge special key press from datagrid to form
Hola amigo(a), I suffered to reach this conclusion , i hope this helps you (my english not is good):
1.- Fisrt create a class and copy this
VB Code:
Public Class MyDataGrid
Inherits DataGrid
Public Event MyKeyDown(ByVal KeyCode As Keys)
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
RaiseEvent MyKeyDown(keyData)
End Function
End Class
2.-Ready.. only create a single grid and the region code to the form change this:
VB Code:
Friend WithEvents Grid As DataGrid
For this :
VB Code:
Friend WithEvents Grid As MyDataGrid
3.-Finally you can doit the new method MyKeyDown(This event catch all keys ;) )
VB Code:
Private Sub Grid_MyKeyDown(ByVal KeyCode As System.Windows.Forms.Keys) Handles Grid.MyKeyDown
Select Case KeyCode
Case Keys.F8
.............
Case Keys.F2
..............
Case Keys.Return
..............
End Sub
Re: how to bridge special key press from datagrid to form
thx a million for your reply,
i will give it a try and i pray it will work,
if this works fine for me, believe me i will be thankfull for a long time.
RGDS
Re: how to bridge special key press from datagrid to form
it works like Magic,
thx a Millioooooooooooooooooooooooon,
:thumb: :thumb: :thumb: :thumb: :thumb: :thumb:
You don't know how much your help is appreciated
C U SOON
Re: how to bridge special key press from datagrid to form
Not problem ,:wave:
Now, only mark your post with (Resolved) :)
Saludos desde México !
Re: [RESOLVED] how to bridge special key press from datagrid to form (resolved)
It really works like HELL...