Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Search in combobox or listbox for a string
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 8th, 2003 04:10 AM    Post subject: Search in combobox or listbox for a string Reply with quote

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 :

Code:
Option Explicit
Private Const CB_FINDSTRING = &H14C
Private Const LB_FINDSTRING = &H18F
Private Declare Function SendMessage Lib _
    "user32" Alias "SendMessageA" (ByVal _
    hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Any) _
    As Long

Private Sub Command1_Click()
    FindCB Combo1, Text1.Text
End Sub

Private Sub Command2_Click()
    FindLB List1, Text1.Text
End Sub

Private Sub Form_Load()
    Command1.Caption = "Find in Combo Box"
    Command2.Caption = "Find in List Box"

    Combo1.AddItem "one"
    Combo1.AddItem "two"
    Combo1.AddItem "three"
    Combo1.AddItem "four"
    Combo1.AddItem "five"
    Combo1.AddItem "six"
    Combo1.AddItem "seven"

    List1.AddItem "one"
    List1.AddItem "two"
    List1.AddItem "three"
    List1.AddItem "four"
    List1.AddItem "five"
    List1.AddItem "six"
    List1.AddItem "seven"
End Sub

Private Sub FindLB(obj As Object, TextToFind As String)
    obj.ListIndex = SendMessage( _
       obj.hwnd, LB_FINDSTRING, -1, ByVal _
       TextToFind)
End Sub

Private Sub FindCB(obj As Object, TextToFind As String)
    obj.ListIndex = SendMessage( _
       obj.hwnd, CB_FINDSTRING, -1, ByVal _
       TextToFind)
End Sub
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic