Results 1 to 16 of 16

Thread: Not Resolved -> KeyDown or KeyPress Not always working

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Not Resolved -> KeyDown or KeyPress Not always working

    I have a MSHFlexGrid, but the KeyPress or KeyDown methods don't always work.

    E.G. You can see that the grid has focus. But when you press the Insert Key, on the keyboard, it doesn't always trigger the KeyDown Event, it does most of the time but not always. Same if the grid has focus and you press a letter, it doesn't always trigger the KeyPress Event.

    Why is this?
    Last edited by mel_flynn; Apr 22nd, 2004 at 04:55 AM.
    Mel

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Can anyone shed any light on this matter? It's quite important. Why would pressing a key on the keyboard not trigger the KeyDown or KeyPress Events?
    Mel

  3. #3
    Hyperactive Member Frodo_Baggins's Avatar
    Join Date
    Feb 2004
    Location
    Sao Paulo, Brazil
    Posts
    397
    Im not pretty sure, but when I used to work with the KeyPress event on forms, I would always adjust the KeyPreview property of the Form to true. Maybe that will help --- but Im not pretty sure.

  4. #4
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    Just for the heck of it... try setting the KeyPreview of the form to TRUE. In the form's KeyDown event, test the VBKeyInsert and pass the code as required.
    Never tie a rock to your ankle while randomly selecting stones to throw from high places.

  5. #5
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    Frodo

    Sorry... you beat me to the punch. Didn't mean to reiterate.
    Never tie a rock to your ankle while randomly selecting stones to throw from high places.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    I tried setting the KeyPreview on the form to true, but still, sometimes, when I press a key when my grid has focus, it's not triggering the KeyDown or KeyPress Event of the Grid.

    This is driving me mad
    Mel

  7. #7
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    Haven't worked much with FlexGrid... are you sure you have the latest upgrades and patches?
    Never tie a rock to your ankle while randomly selecting stones to throw from high places.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Well I'm running VB6 (SP5), I think that's the latest??
    Mel

  9. #9
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    Ok... I'll work with it and get back to you. In the mean time, maybe someone else will post an answer.
    Never tie a rock to your ankle while randomly selecting stones to throw from high places.

  10. #10
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    I'm not sure there is a KeyAscii equilalent to the Insert Key, therefore; Keypress will fail...

    Use KeyDown and KeyUp instead... to prove the point... create a new project and install a FlexGrid named MSFlexGrid1. Add the following:

    VB Code:
    1. Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     'Will be received
    3.     If KeyCode = vbKeyInsert Then
    4.         MsgBox "I've got KeyDown focus"
    5.     End If
    6.    
    7. End Sub
    8.  
    9. Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    10.     'will not be received
    11.     If KeyAscii = vbKeyInsert Then
    12.         MsgBox "I've got KeyPress focus"
    13.     End If
    14.  
    15. End Sub
    Never tie a rock to your ankle while randomly selecting stones to throw from high places.

  11. #11
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    SP6 is out


    Originally posted by mel_flynn
    Well I'm running VB6 (SP5), I think that's the latest??

  12. #12
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Can you recreate the problem or does it happen randomly?
    Is the flexgrid data bound?
    Does the flexgrid really have the focus?

    Try the KeyPreview property of the Form again. Put this code in the Form_KeyDown event.

    Debug.print Me.ActiveControl.Name, vbkeycode

    Then, when it seems the Insert key is not being recognized by the FlexGrid, this will display the name of the control that has the focus. At least you will know if it is a flex grid problem or caused elsewhere.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    I'm not sure there is a KeyAscii equilalent to the Insert Key, therefore; Keypress will fail...
    I realise this, I am using the KeyDown to trap Non-alphanumeric keys like INSERT; ENTER; DELETE etc, and I am using the the KeyPress Event to trap all alphanumeric keys.
    SP6 is out
    I don't think that this is the problem.
    Can you recreate the problem or does it happen randomly?
    Is the flexgrid data bound?
    Does the flexgrid really have the focus?
    1. I can't intentionally recreate it, it's happening randomly, not sure what's triggering it to happen.
    2. The MSHFlexgrid isn't databound, I'm populating it by adding the data to the grid with a loop.
    3. Yes the grid has focus as when I arrow left, right, up or down it moves from cell to cell, but again doesn't trigger the KeyDown event.
    Mel

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    OK really weird. I'm stepping through the code now and it's not calling the KeyDown Event when I press INSERT; DELETE or RETURN, but it will call the KeyDown Event when I press any of the arrows, or the PageUp and Down Key or the Home and End Keys. It will call it when I press Alt but not when I press Ctrl. It will call it when I press F10 but won't for any other F- Key. It won't call it for ESC.

    Why is this?????
    Mel

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Anyone?
    Mel

  16. #16
    Hyperactive Member D12Bit's Avatar
    Join Date
    Oct 2000
    Location
    Guatemala
    Posts
    373
    yes... for the use of the INSERT and DELETE and HOME, etc ...
    you need to trap the KeyCode ... I don't have at hand the list of keys that you only get to catch thru KeyDown

    but I use the KeyDown in a ListView to trap INSERT (45) and DELETE (46) to add and to delete entries in it.

    btw,
    do a search for "keycode constants" inside MSDN ...and you'll get the list of them
    "Who Dares Wins" - "Quien se Arriesga Gana"
    Mail me at:

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