Results 1 to 9 of 9

Thread: [RESOLVED] how to bridge special key press from datagrid to form (resolved)

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Resolved [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:
    1. select case e.keycode
    2.  
    3. case 112
    4.    'save code
    5. case 113
    6.    'delete code
    7. case 114
    8.  'add new code
    9. 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
    Last edited by maged; Jun 5th, 2005 at 02:53 PM.

  2. #2
    Addicted Member garyjohn_2000's Avatar
    Join Date
    Apr 2005
    Location
    Timbaland
    Posts
    243

    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!

  3. #3

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    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

    VB Code:
    1. msgbox("beep")

    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

  4. #4

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: how to bridge special key press from datagrid to form

    bump

  5. #5
    New Member
    Join Date
    Jun 2005
    Posts
    7

    Talking 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:
    1. Public Class MyDataGrid
    2.     Inherits DataGrid
    3.     Public Event MyKeyDown(ByVal KeyCode As Keys)
    4.  
    5.     Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    6.         RaiseEvent MyKeyDown(keyData)
    7.     End Function
    8.  
    9. End Class

    2.-Ready.. only create a single grid and the region code to the form change this:
    VB Code:
    1. Friend WithEvents Grid As DataGrid

    For this :

    VB Code:
    1. Friend WithEvents Grid As MyDataGrid

    3.-Finally you can doit the new method MyKeyDown(This event catch all keys )

    VB Code:
    1. Private Sub Grid_MyKeyDown(ByVal KeyCode As System.Windows.Forms.Keys) Handles Grid.MyKeyDown
    2.         Select Case KeyCode
    3.             Case Keys.F8
    4.                      .............
    5.             Case Keys.F2
    6.                     ..............
    7.             Case Keys.Return
    8.                     ..............
    9. End Sub

  6. #6

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    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

  7. #7

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: how to bridge special key press from datagrid to form

    it works like Magic,


    thx a Millioooooooooooooooooooooooon,



    You don't know how much your help is appreciated

    C U SOON

  8. #8
    New Member
    Join Date
    Jun 2005
    Posts
    7

    Re: how to bridge special key press from datagrid to form

    Not problem ,

    Now, only mark your post with (Resolved)


    Saludos desde México !
    Last edited by jorgegc; Jun 11th, 2005 at 11:53 AM.

  9. #9
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: [RESOLVED] how to bridge special key press from datagrid to form (resolved)

    It really works like HELL...

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