ListBox, ComboBox 寻找字串
作者: VB Knowledge Base
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 Form_Load()
List1.Clear
List1.AddItem "Apples"
List1.AddItem "Banana"
List1.AddItem "Bread"
List1.AddItem "Break"
Text1.Text = ""
End Sub
Private Sub Text1_Change()
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, _
ByVal CStr(Text1.Text))
End Sub
用在 ComboBox也可以
只要将 SendMessage中的 LB_FINDSTRING 换成 CB_FINDSTRINGEXACT即可
Public Const CB_FINDSTRINGEXACT& = &H158