Results 1 to 3 of 3

Thread: Listbox

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Listbox

    Hey,

    I have a question about the listbox control.
    When it has focus, and you press a letter on teh keyboard, it will automatically search for the first item that begins with that letter.

    Is there a way I can trap more then one key press??

    I want the search to be more accurate.

    Thanks,
    Don't anthropomorphize computers -- they hate it

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Add a timer and set an interval to it.

    VB Code:
    1. Dim PressedKeys As String
    2.  
    3. Private Sub Timer1_Timer()
    4.     Timer1.Enabled = False
    5.     Do While LenB(PressedKeys) > 0
    6.         For A = 0 To List1.ListCount - 1
    7.             If InStr(1, List1.List(A), PressedKeys, vbTextCompare) = 1 Then
    8.                 List1.ListIndex = A
    9.                 PressedKeys = vbNullString
    10.                 Exit Sub
    11.             End If
    12.         Next A
    13.         PressedKeys = Mid$(PressedKeys, 1, Len(PressedKeys) - 1)
    14.     Loop
    15. End Sub
    16.  
    17. Private Sub List1_KeyPress(KeyAscii As Integer)
    18.     PressedKeys = PressedKeys & ChrW$(KeyAscii)
    19.     Timer1.Enabled = False
    20.     Timer1.Enabled = True
    21.     'prevent the default search from happening
    22.     KeyAscii = 0
    23. End Sub

    Didn't test the code, but is should work

  3. #3

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