Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ListView Custom Search Filter - List(Of T) Method
#1
I also have a predicate method, but this works well and should be easy to understand, for those of you who leech and probably don't understand this, well I hope it works for you lol, and to those that don't understand but want to know more about my code, just reply and i'll respond.

Code:
Public Class Form1

    Public SearchText As String
    Public _data() As String = {"1_one,1_two,1_three", "2_one,2_sdf,2_three", "3_one,3_sdf,3_three"}
    Public Arr As New List(Of String)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Arr.AddRange(_data)

        For Each obj As String In Arr
            Dim Sdata() As String = obj.Split(","c)
            Dim LVC As New ListViewItem(Sdata)
            ListView1.Items.Add(LVC)
        Next

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SearchText = TextBox1.Text

        Dim Arr_Modified As New List(Of String)
        Arr_Modified.AddRange(Arr)

        For Each ObjNewStr As String In Arr
            'If not middle value in array contains search value
            If Not ObjNewStr.Split(","c)(1).Contains(SearchText) Then
                Arr_Modified.Remove(ObjNewStr)
            End If
        Next

        ListView1.Items.Clear()
        For Each ObjNewStr As String In Arr_Modified
            Dim StrSplit() As String = ObjNewStr.Split(","c)
            Dim Mod_LVC As New ListViewItem(StrSplit)
            ListView1.Items.Add(Mod_LVC)
        Next

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        SearchText = TextBox1.Text

        Dim Arr_Modified As New List(Of String)
        Arr_Modified.AddRange(Arr)

        For Each ObjNewStr As String In Arr
            'If not middle value in array contains search value
            If Not ObjNewStr.Split(","c)(1).Contains(SearchText) Then
                Arr_Modified.Remove(ObjNewStr)
            End If
        Next

        ListView1.Items.Clear()
        For Each ObjNewStr As String In Arr_Modified
            Dim StrSplit() As String = ObjNewStr.Split(","c)
            Dim Mod_LVC As New ListViewItem(StrSplit)
            ListView1.Items.Add(Mod_LVC)
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Test Button for Debugging
    End Sub
End Class
Reply


Messages In This Thread
ListView Custom Search Filter - List(Of T) Method - by AceInfinity - 12-29-2011, 03:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [NEED HELP] how to read a text file and import to listview vb.net w00pz 7 6,371 02-13-2012, 06:42 AM
Last Post: AceInfinity
  Drag and Drop to Listview [Tutorial] AceInfinity 3 2,861 09-03-2011, 05:29 AM
Last Post: .edit
  [Help] - ListView Control Fragma 2 1,145 08-19-2011, 05:10 AM
Last Post: Fragma

Forum Jump:


Users browsing this thread: 3 Guest(s)