Results 1 to 3 of 3

Thread: VB - Search in combobox or listbox for a string

Threaded View

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    VB - Search in combobox or listbox for a string

    Add a listbox (List1) and a combobox (Combo1), a textbox (Text1) and two command buttons (Command1 , Command2) to your form and add the following code :

    VB Code:
    1. Option Explicit
    2. Private Const CB_FINDSTRING = &H14C
    3. Private Const LB_FINDSTRING = &H18F
    4. Private Declare Function SendMessage Lib _
    5.     "user32" Alias "SendMessageA" (ByVal _
    6.     hwnd As Long, ByVal wMsg As Long, _
    7.     ByVal wParam As Long, lParam As Any) _
    8.     As Long
    9.  
    10. Private Sub Command1_Click()
    11.     FindCB Combo1, Text1.Text
    12. End Sub
    13.  
    14. Private Sub Command2_Click()
    15.     FindLB List1, Text1.Text
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.     Command1.Caption = "Find in Combo Box"
    20.     Command2.Caption = "Find in List Box"
    21.  
    22.     Combo1.AddItem "one"
    23.     Combo1.AddItem "two"
    24.     Combo1.AddItem "three"
    25.     Combo1.AddItem "four"
    26.     Combo1.AddItem "five"
    27.     Combo1.AddItem "six"
    28.     Combo1.AddItem "seven"
    29.  
    30.     List1.AddItem "one"
    31.     List1.AddItem "two"
    32.     List1.AddItem "three"
    33.     List1.AddItem "four"
    34.     List1.AddItem "five"
    35.     List1.AddItem "six"
    36.     List1.AddItem "seven"
    37. End Sub
    38.  
    39. Private Sub FindLB(obj As Object, TextToFind As String)
    40.     obj.ListIndex = SendMessage( _
    41.        obj.hwnd, LB_FINDSTRING, -1, ByVal _
    42.        TextToFind)
    43. End Sub
    44.  
    45. Private Sub FindCB(obj As Object, TextToFind As String)
    46.     obj.ListIndex = SendMessage( _
    47.        obj.hwnd, CB_FINDSTRING, -1, ByVal _
    48.        TextToFind)
    49. End Sub
    Last edited by manavo11; Mar 13th, 2003 at 07:32 AM.


    Has someone helped you? Then you can Rate their helpful post.

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