Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 563215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:38:11+00:00 2026-05-13T12:38:11+00:00

I am trying to search through items in listview control in vb.net one by

  • 0

I am trying to search through items in listview control in vb.net one by one. i.e When the user types in some keyworrk in the textbox and presses enter, the first found item in the listview should get highlighted, when he presses enter again, the second search item in the listview should get highlighted and so on.

I am not fully aware of how to keep track of already found items while searching. As of now , I am searching all the items in the listbx using the code :

   If (e.KeyCode = Keys.Enter) Then
                'START


        ListView1.BeginUpdate()
        ListView1.SelectedIndices.Clear()
        If TextBox1.Text.Length > 0 Then
            Dim lstOfStrings() As String = TextBox1.Text.Split(","c)
            For Each s As String In lstOfStrings
                For index As Integer = 0 To ListView1.Items.Count - 1

                    If s.Trim() <> "" Then

                        Dim item As String = ListView1.Items(index).ToString()

                        If item.IndexOf(s, StringComparison.CurrentCultureIgnoreCase) >= 0 Then

                            'ListView1.SelectedIndices.Add(index)
                            ListView1.Items(index).BackColor = Color.LightPink
                        End If
                    End If
                Next
            Next s
        End If
        ListView1.EndUpdate()
End if
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:38:11+00:00Added an answer on May 13, 2026 at 12:38 pm

    This does exactly what you want:
    Just call FindInListView function when the user press enter, the same function can be used with more than one listview!
    I added also a “FindInGrid” function it does exactly the same but with DataGrids.

            Private DicPos As New Dictionary(Of Integer, Integer)
    
        Public Function FindInListView(ByVal lv As ListView, ByVal Texto As String) As Integer
    
            If Not DicPos.ContainsKey(lv.Handle) Then
                DicPos.Add(lv.Handle, -1)
    
            End If
            If lv.Items.Count = 0 Then Return 0
            Texto = Texto.Trim.ToUpper
            If Texto.Length = 0 Then lv.Items(0).Selected = True
            Dim Itm As ListViewItem
            For x As Integer = DicPos(lv.Handle) + 1 To lv.Items.Count - 1
                Itm = lv.Items(x)
                For Each cell As ListViewItem.ListViewSubItem In Itm.SubItems
                    If cell.Text.ToUpper.Contains(Texto) Then
                        lv.Items(x).Selected = True
                        Try
                            lv.BindingContext.Item(lv.DataBindings).Position = x
                        Catch ex As Exception
                        End Try
                        DicPos(lv.Handle) = Itm.Index
                        Return DicPos(lv.Handle)
                    End If
                Next
            Next
            If DicPos(lv.Handle) = -1 Then
                lv.BindingContext.Item(lv.DataBindings).Position = 0
                Return DicPos(lv.Handle)
            Else
                DicPos(lv.Handle) = -1
                Return FindInListView(lv, Texto)
            End If
    
        End Function
    
        Public Function FindInGrid(ByVal Grid As DataGridView, ByVal Texto As String, ByVal Position As Integer) As Integer
            Texto = Texto.Trim.ToUpper
            If Texto.Length = 0 Then
                Grid.BindingContext.Item(Grid.DataSource).Position = 0
                Return 0
            End If
            For x As Integer = Position To Grid.Rows.Count - 1
                For Each Cel As DataGridViewCell In Grid.Rows(x).Cells
                    If Cel.Value.ToString.ToUpper.Contains(Texto) Then
                        Grid.Rows(Cel.RowIndex).Selected = True
                        Try
                            Grid.BindingContext.Item(Grid.DataSource).Position = x
                        Catch ex As Exception
    
                        End Try
                        Return Cel.RowIndex
                    End If
                Next
            Next
            If Position = 0 Then
                Grid.BindingContext.Item(Grid.DataSource).Position = 0
                Return 0
            Else
                Return FindInGrid(Grid, Texto, 0)
            End If
        End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to search through listview in VB.net 2008. It works fine with
I'm trying to basically do a search through the database with Perl to tell
I'm trying to search using the windows search one of my web directories for
I'm new to Python and I have been trying to search through html with
I'm trying to make a list of all items in a binary search tree.
I am trying to search through a binary search tree and store each node
I am trying to find a way to search through a page in php
I'm trying to search multiple attributes in XML : <APIS> <API Key=00001> <field Username=username1
I'm trying to implement search result highlighting for pdfs in a web app. I
I'm trying to get a case-insensitive search with two strings in JavaScript working. Normally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.