Click to See Complete Forum and Search --> : ListView Not Responding to Tab Key


Anna Nagarajan
April 16th, 2001, 12:50 PM
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

Iouri
April 16th, 2001, 01:12 PM
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
iouri@hotsheet.com