Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 过滤非常长的列表视图_Vb.net_Sorting_Listview_Listviewitem - Fatal编程技术网

Vb.net 过滤非常长的列表视图

Vb.net 过滤非常长的列表视图,vb.net,sorting,listview,listviewitem,Vb.net,Sorting,Listview,Listviewitem,伙计们 我正在为学校做一个项目,我试图找出解决ListView中条目过滤/搜索问题的最佳方法 我目前有一个名为lvCard的ListView控件,它在从FormLoad上的JSON文件填充后需要进行过滤,其中包含大约15000个条目。它是一个多列ListView详细视图,基本上包含了收集卡片所产生的每一个魔力 我还有一个搜索框,名为txtSearch 我知道基本上,我需要在搜索框的更改事件上附加一些功能,但是在那之后,我有点迷路了 目前,我所拥有的只是我编写的一个子例程,它在应用程序启动时填充目

伙计们

我正在为学校做一个项目,我试图找出解决ListView中条目过滤/搜索问题的最佳方法

我目前有一个名为lvCard的ListView控件,它在从FormLoad上的JSON文件填充后需要进行过滤,其中包含大约15000个条目。它是一个多列ListView详细视图,基本上包含了收集卡片所产生的每一个魔力

我还有一个搜索框,名为txtSearch

我知道基本上,我需要在搜索框的更改事件上附加一些功能,但是在那之后,我有点迷路了

目前,我所拥有的只是我编写的一个子例程,它在应用程序启动时填充目标ListView,我想它提供了一些关于如何设置目标ListView的见解,但除此之外,我真的很困惑,可以肯定地使用一些指导

' Render the whole list of stuff
Private Sub RenderList(dict As Dictionary(Of String, Card))

    ' Grab keys into list for sorting
    Dim lstCards As List(Of String) = dict.Keys.ToList
    lstCards.Sort()

    ' iteration
    Dim str As String
    For Each str In lstCards

        Dim CurrentCard As Card = dict(str)

        Dim CurrentPT As String
        If IsNumeric(CurrentCard.power) And IsNumeric(CurrentCard.toughness) Then
            CurrentPT = CurrentCard.power & "/" & CurrentCard.toughness
        Else
            CurrentPT = ""
        End If

        ' Build list item
        Dim CurrentItem As New ListViewItem(CurrentCard.name)
        CurrentItem.SubItems.Add(CurrentCard.manaCost)
        CurrentItem.SubItems.Add(CurrentCard.type)
        CurrentItem.SubItems.Add(CurrentPT)
        lvCard.Items.Add(CurrentItem)

    Next

End Sub

我不知道这是否有效,因为我目前无法测试它,我也不知道这是最有效的方法,但您可以向RenderList sub添加另一个ByVal,然后将搜索项传递给它,如下所示:

Private Sub RenderList(ByVal dict As Dictionary(Of String, Card), ByVal Optional search As String = Nothing)
    If search Is Not Nothing Then
       'Grab SEARCHED keys into list for sorting

       'Populate the initial list first
        Dim lstCards As List(Of String) = dict.Keys.ToList

        'Create a new list to contain all found items
        Dim newLst As List(Of String)

        For Each item As String In lstCards
            If item.ToLower.Contains(search.ToLower) Then
                newLst.Add(item)
            End If
        Next

        'Set lstCards to the new list of items
        lstCards = newLst
        lstCards.Sort()
    Else
        'Grab ALL keys into list for sorting
        Dim lstCards As List(Of String) = dict.Keys.ToList
        lstCards.Sort()
    End If

    /.../

End Sub
然后使用RenderListmycards,TextBox1.Text添加到您的TextBox1.TextChanged事件中