VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - ListBox, ComboBox 寻找字串
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:12820, 日期:2001-09-16
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