CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2000
    Location
    USA
    Posts
    33

    ListView Not Responding to Tab Key

    Hi everyone,

    How do I recognize that a tab key is pressed when listview control has focus. I tried key press event

    if Keyascii = 9 then'tab key
    keyascii = 0
    end if

    But, this event is not triggered at all. Any help will be greatly appreciated.

    Thanks,
    Anna



  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: ListView Not Responding to Tab Key

    Catching keys (tab, arrows) without subclassing is not easy.

    Form_KeyDown (or Form_KeyUp) will not catch all keys always.

    If form has no controls, it will work.
    If you add one textbox, it will work.

    If you add second textbox, it will work for arrow keys, but Tab key will be 'eaten'.

    If you add few buttons, VB will allow you to use arrow keys for navigation between buttons. But then
    ... Form_KeyDown will not be able to catch these arrow keys.

    Here is the solution - it uses one API. You will be able to catch Tab key row . If Form_KeyDown is not able to receive a key, keyCheckTab will do it.




    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer


    Private Sub List1_LostFocus()
    keyCheckTab
    End Sub


    Private Sub keyCheckTab()
    If GetKeyState(vbKeyTab) < 0 Then
    MsgBox "Tab pressed"
    End If
    End Sub


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured