P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Oct 10th, 2003 08:14 AM Post subject: Search in combobox or listbox for a string, API way |
|
|
| Code: | Option Explicit
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 Const CB_FINDSTRING = &H14C
Private Const LB_FINDSTRING = &H18F
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(LB As ListBox, TextToFind As String)
LB.ListIndex = SendMessage( _
LB.hwnd, LB_FINDSTRING, -1, ByVal _
TextToFind)
End Sub
Private Sub FindCB(CB As ComboBox, TextToFind As String)
CB.ListIndex = SendMessage( _
CB.hwnd, CB_FINDSTRING, -1, ByVal _
TextToFind)
End Sub |
_________________ No one is completely useless. They can at least be an example of what to avoid. |
|