Results 1 to 3 of 3

Thread: Firefox style Search

  1. #1

    Thread Starter
    Hyperactive Member MeTTa@'s Avatar
    Join Date
    Aug 2005
    Posts
    312

    Firefox style Search

    I made one a long time ago, and miss it misrably

    I have a list box, and a text field(for searching), and while you type it filters the list items that contain what your typing. Could some recreate this, its a fun project and i just cant figure it out again. Thanks,
    ___
    Dan

  2. #2
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Firefox style Search

    This might help...


    VB Code:
    1. Option Explicit
    2. 'API sendmessage to listbox
    3. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    4.     ByVal hwnd As Long, _
    5.     ByVal wMsg As Long, _
    6.     ByVal wParam As Long, _
    7.     ByRef lParam As Any _
    8. ) As Long
    9. Const LB_FINDSTRING = &H18F
    10. Dim delKey As Boolean
    11. Dim boolClick As Boolean
    12.  
    13. Private Sub Form_Load()
    14. With List1
    15.     .AddItem "one"
    16.     .AddItem "two"
    17.     .AddItem "three"
    18.     .AddItem "four"
    19.     .AddItem "five"
    20.     .AddItem "six"
    21.     .AddItem "seven"
    22.     .AddItem "eight"
    23.     .AddItem "nine"
    24.     .AddItem "ten"
    25. End With
    26. End Sub
    27.  
    28. Private Sub List1_Click()
    29. 'to prevent executing the click event
    30.  If boolClick Then Exit Sub
    31.     Text1.Text = List1.Text
    32. End Sub
    33.  
    34. Private Sub List1_GotFocus()
    35.     SendKeys "{DOWN}"
    36. End Sub
    37.  
    38. Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
    39.     List1_Click
    40. End Sub
    41.  
    42. Private Sub Text1_Change()
    43. 'autocomplete feature
    44. Dim strt As Long
    45.    
    46.     boolClick = True
    47.  
    48.     'Retrieve the item's listindex
    49.     List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
    50.    
    51.     If Not delKey Then
    52.  
    53.         If List1.ListIndex <> -1 Then
    54.             strt = Len(Text1.Text)
    55.             Text1.Text = List1.List(List1.ListIndex)
    56.             Text1.SelStart = strt
    57.             Text1.SelLength = Len(Text1.Text) - strt
    58.         End If
    59.     End If
    60.    
    61.        delKey = False
    62.        boolClick = False
    63.  
    64. End Sub
    65.  
    66. Private Sub Text1_Click()
    67.     'select all the text
    68.     Text1.SelStart = 0
    69.     Text1.SelLength = Len(Text1)
    70. End Sub
    71.  
    72. Private Sub text1_KeyDown(KeyCode As Integer, Shift As Integer)
    73.     'for delete and backspace
    74.     If KeyCode = vbKeyDelete Or KeyCode = 8 Then
    75.    
    76.     delKey = True
    77.     Exit Sub
    78.  
    79.     ElseIf KeyCode = vbKeyDown Then
    80.         List1.SetFocus
    81.     ElseIf KeyCode = vbKeyUp Then
    82.         List1.SetFocus
    83.         SendKeys "{UP 2}"
    84.     End If
    85. End Sub


  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