首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

50分 求ListView 搜索函数的使用实例,该如何解决

2012-01-24 
50分 求ListView 搜索函数的使用实例ListView搜索函数如下哪位能给个实例吗?我正要用它,谢谢啊!函数名:Sea

50分 求ListView 搜索函数的使用实例
ListView   搜索函数如下
哪位能给个实例吗?我正要用它,谢谢啊!

'   函数名:     SearchListView
'   描述:ListView   搜索函数
'日期:2005.03.05
'**************************************

Option   Explicit
Public   Sub   SearchListView(ListViewX   As   ListView,   SearchString   As   String,   ListViewZ   As   ListView)
        On   Error   Resume   Next
        Dim   w,   x,   y,   z   As   Integer
        Dim   a,   b   As   String
        ListViewX.ListItems.Add   ,   ,   "   "
        ListViewX.ListItems.Item(1).Selected   =   True
        SearchString   =   LCase(SearchString)


        Do   Until   ListViewX.SelectedItem.Index   =   ListViewX.ListItems.Count
                a   =   LCase(ListViewX.SelectedItem.Text)
                z   =   Len(a)
                y   =   Len(SearchString)


                For   x   =   1   To   z


                        If   Mid(a,   x,   y)   =   SearchString   Then


                                If   ListViewX.SelectedItem   =   b   Then
                                Else
                                        ListViewZ.ListItems.Add   ,   ,   ListViewX.SelectedItem
                                        b   =   ListViewX.SelectedItem
                                End   If
                        End   If
                Next   x
                w   =   ListViewX.SelectedItem.Index
                w   =   w   +   1
                ListViewX.ListItems.Item(w).Selected   =   True
        Loop
        ListViewX.ListItems.Remove   (ListViewX.ListItems.Count)
End   Sub

[解决办法]
窗体上两个listview,一个按钮:

Option Explicit
Public Sub SearchListView(ListViewX As ListView, SearchString As String, ListViewZ As ListView)
On Error Resume Next
Dim w, x, y, z As Integer
Dim a, b As String
ListViewX.ListItems.Add , , " "
ListViewX.ListItems.Item(1).Selected = True
SearchString = LCase(SearchString)


Do Until ListViewX.SelectedItem.Index = ListViewX.ListItems.Count


a = LCase(ListViewX.SelectedItem.Text)
z = Len(a)
y = Len(SearchString)


For x = 1 To z


If Mid(a, x, y) = SearchString Then


If ListViewX.SelectedItem = b Then
Else
ListViewZ.ListItems.Add , , ListViewX.SelectedItem
b = ListViewX.SelectedItem
End If
End If
Next x
w = ListViewX.SelectedItem.Index
w = w + 1
ListViewX.ListItems.Item(w).Selected = True
Loop
ListViewX.ListItems.Remove (ListViewX.ListItems.Count)
End Sub

Private Sub Command1_Click()
SearchListView ListView1, "test ", ListView2
End Sub

Private Sub Form_Load()
Dim i As Long
For i = 0 To 20
ListView1.ListItems.Add Text:= "line " & CStr(i)
ListView1.ListItems.Add Text:= "test " & CStr(i)
Next
End Sub

热点排行