本文主要是介绍Vb查找ListBox列表数据,在原列表中显示查找到的数据。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
'在窗体中画三个控件(Text1、Command1、List1),属性为默认,加入以下代码:
Option Explicit
Private Sub FindThe(List As ListBox, Txt As String, N As Boolean)
Static Sstxt() As String, S(2) As Integer, Lt As Boolean
If N Then
If Lt = False Then
For S(0) = 0 To List.ListCount - 1
ReDim Preserve Sstxt(S(0))
Sstxt(S(0)) = List.List(S(0)) '先将列表所有数据放到数组Sstxt中,方便导回列表。
If S(0) = List.ListCount - 1 Then List.Clear: Lt = True
Next S(0)
End If
If Lt = True Then
List.Clear
For S(1) = LBound(Sstxt) To UBound(Sstxt)
If InStr(UCase(Sstxt(S(1))), UCase(Txt)) <> 0 Then
List.AddItem Sstxt(S(1))
End If
Next S(1)
End If
Else
Dim i As Integer
If Text1 = “” And Lt = True Then
List1.Clear
For i = LBound(Sstxt) To UBound(Sstxt)
List1.AddItem Sstxt(i)
If i >= UBound(Sstxt) Then Erase Sstxt: Lt
这篇关于Vb查找ListBox列表数据,在原列表中显示查找到的数据。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!