微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

你如何在列表视图中使用关键字进行搜索?

如何解决你如何在列表视图中使用关键字进行搜索?

我一直在想怎么做 1;搜索我需要获得匹配项和 2 的项目;如果它还没有结束,让它能够为我提供下一个搜索匹配。而这段代码不能做那些(注意:这段代码搜索按钮中)

我一直在想如何做到这一点,因为我已经尝试了好几天了,我的老师并没有真正给我们太多,她只是告诉我们按照我输入的内容做段落(和 atm 我们都在挣扎,哈哈)

顺便说一下,我需要立即答复!

Dim searchText = Me.TextBox4.Text

        If searchText = String.Empty Then
            'Don't bother searching if there's no text to search for.
            MessageBox.Show("Please enter search text.")
        Else
            Dim startIndex = 0
            Dim item As ListViewItem = nothing

            'If one item is selected and it already matches the search text,''start searching from the next item.
            'Otherwise,start searching from the beginning.
            If Me.ListView1.SelectedItems.Count = 1 AndAlso Me.ListView1.SelectedItems(0).Text = searchText Then
                startIndex = Me.ListView1.Selectedindices(0) + 1
            End If

            'Don't search if we're already at the end of the items.
            If startIndex < Me.ListView1.Items.Count Then
                Do
                    'Find the first partial match.
                    item = Me.ListView1.FindItemWithText(searchText,False,startIndex)

                    If item Is nothing OrElse item.Text = searchText Then
                        'There is no partial match or we have already found a full match.
                        Exit Do
                    End If

                    'Search again from the item after the last partial match.
                    startIndex = item.Index + 1

                    'Stop searching if we're at the end of the items.
                    If startIndex >= Me.ListView1.Items.Count Then
                        Exit Do
                    End If
                Loop
            End If

            'Clear the current selection.
            Me.ListView1.SelectedItems.Clear()

            If item Is nothing Then
                MessageBox.Show("No match found.")
            Else
                'Select the matching item.
                item.Selected = True
                item.EnsureVisible()
                Me.ListView1.Select()
            End If
        End If

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。