Search Listview?
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
10 posts
Page 1 of 1
Hello,
Im trying to know what would be a listview version of code that Usman55 posted
Im trying to know what would be a listview version of code that Usman55 posted
Code: Select all
which is under Textbox1_textchangedDim Contact As String = TextBox1.Text.ToString()
Dim Index As Integer = ListBox1.FindString(Contact)
If Index = -1 Then
ListBox1.SelectedIndex = ListBox1.SelectedIndex
Else
ListBox1.SetSelected(Index, True)
End If
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

Do you wanna search subitems too ?
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
Code: Select all
Not sure if this works , but you may give it a try ;)Shared function Searchlistview as boolean(ByVal stringtosearch as string)
For I as integer =0 To listview.Items.Count -1
For X as integer =0 To listview.Items(I).Subitems.Count -1
If listview.Items(I).Subitems(X).Text.Contains(stringtosearch) Then
listview.Items(I).Selected = true
return true
end if
Next
Next
End function
Oh and I doubt about "Subitems(X).Text.Contains(stringtosearch)" don't know if that's right
Try:
Code: Select all
Not sure if it will work, tell me if it does.Dim sItems As Integer
sItems = ListView1.SubItems.Count
For i = 0 To sItems - 1
If ListView1.Items.Item(i).Contains(string) Then
MsgBox("Found at Item " & i)
Elseif ListView1.Items.Item(i).SubItem(i).Contains(string) Then
MsgBox("Found at Subitem " & i)
End If
Next
Axel's code seems to contain some syntax errors in the function declaration.
Reboh's code doesn't work as there is no SubItems object in the listview control.
If you only want to search the first column then the code should look like this:
Reboh's code doesn't work as there is no SubItems object in the listview control.
If you only want to search the first column then the code should look like this:
Code: Select all
Dim found As Integer = -1
For i As Integer = 0 To ListView1.Items.Count - 1
If ListView1.Items(i).Text.Contains(txtFind.Text) Then
found = i
Exit For
End If
Next
If found > -1 Then
ListView1.Items(found).Selected = True
ListView1.Select()
End If
Last edited by mandai on Mon Apr 18, 2011 9:04 pm, edited 1 time in total.
mandai wrote: Axel's code seems to conatin some syntax errors in the function declaration.Axel's code contains .SubItems after a full-stop. Mine contains .SubItem. You said that I used SubItems, but I didn't. Why doesn't mine work (as in, what error?)
Reboh's code doesn't work as there is no SubItems object in the listview control.
I have attached a screenshot.
You do not have the required permissions to view the files attached to this post.
Oh, I see. I didn't write my code in VB :P I just mocked it up before school in the morning 

Codex wrote:Do you wanna search subitems too ?Yes that would be Great

Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

You could use this to search the whole listview (including subitems):
Code: Select all
It will stop searching after it finds 1 item. Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
Dim found As Integer = -1
For row As Integer = 0 To ListView1.Items.Count - 1
For column As Integer = 0 To ListView1.Items(row).SubItems.Count - 1
If ListView1.Items(row).SubItems(column).Text.Contains(txtFind.Text) Then
found = row
Exit For
End If
Next
If found > -1 Then
Exit For
End If
Next
If found > -1 Then
ListView1.Items(found).Selected = True
ListView1.Select()
End If
End Sub
10 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023