求VB高手帮忙,关于textbox和listbox的

来源:百度知道 编辑:UC知道 时间:2024/06/07 16:39:05
在TEXTBOX里面每输入一个字符,listbox就自动搜索相似的内容类似 VB帮助那种效果

用Instr函数就可以实现您要的程式。

Private Sub Text1_Change()
For i = 0 To List1.ListCount - 1
If InStr(1, List1.List(i), Text1.Text, vbTextCompare) Then
List1.Selected(i) = True
End If
Next
End Sub

Private Sub Form_Load()
For i = 1 To 10
List1.AddItem i
Next
End Sub

Private Sub Text1_Change()
For i = 0 To List1.ListCount - 1
Debug.Print List1.List(i), Text1.Text
If InStr(List1.List(i), Text1.Text) > 0 Then List1.Selected(i) = True
Next
End Sub