1,105,391 Community Members

Listview Search Using a Textbox

Member Avatar
ImZick
Posting Whiz in Training
201 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 4 [?]
 
0
 

Hello need help i have a listview and a textbox
I have this code

ListView_LOB.Focus()
For i = 0 To ListView_LOB.Items.Count - 1
    If ListView_LOB.Items(i).SubItems(1).Text = TextBox1.Text Then
        ListView_LOB.Items(i).Selected = True
    End If
Next

it will highlight the item in Listview it seen in textbox1 for example "Erick"
but if i search again and change the textbox1 example is "Larrie"
it will highlight "Larrie" and also "Erick"

Member Avatar
Reverend Jim
Noli mentula
5,450 posts since Aug 2010
Reputation Points: 761 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

You can either set the ListView MultiSelect property to False, or you can change the code to

ListView_LOP.SelectedIndices.Clear()
ListView_LOB.Focus()

For i = 0 To ListView_LOB.Items.Count - 1
    If ListView_LOB.Items(i).SubItems(1).Text = TextBox1.Text Then
        ListView_LOB.Items(i).Selected = True
    End If
Next
Question Answered as of 1 Year Ago by Reverend Jim
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article