Home > Software design >  Search in already filled listview through textbox by eliminating all other rows except seacrhed row
Search in already filled listview through textbox by eliminating all other rows except seacrhed row

Time:09-23

I have already populated a ListView from a DataTable dt4. I have declared globally and below is my code but code is not giving searched string instead its loading again on any keypress.

Please help me in writing code

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    conn = GetConnect()
    conn.Open()
    
    dt4.Select("ServiceName like '%"   TextBox1.Text   "%' ")

    With ListView3
        .View = View.Details
        .GridLines = True
        .Columns.Clear()
        .Items.Clear()
        .Columns.Add(" ", 30)
        .Columns.Add("CPT Code", 80, HorizontalAlignment.Left)
        .Columns.Add("Service Name", 350, HorizontalAlignment.Left)

        For Each row As DataRow In dt4.Rows
            'Add Item to ListView.
            Dim item As ListViewItem = New ListViewItem
            item.SubItems.Add(row("CPTCode").ToString())
            item.SubItems.Add(row("ServiceName").ToString())                
            item.Checked = False
            .Items.Add(item)
            item = Nothing
        Next
    End With

End Sub

CodePudding user response:

The result of Select should have your sought rows

Dim rows = dt4.Select("ServiceName like '%"   TextBox1.Text   "%' ")

For Each row As DataRow In rows

from DataTable.Select

  • Related