how to search for text in listview?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

Hi,

Need some help with listview, is there a function that can search the
listview for a specified string and return true/false ?


Thanks,
Tee
 
Need some help with listview, is there a function that can search the
listview for a specified string and return true/false ?

Private Function SearchListViewText( _
ByVal searchString As String) As Boolean

For Each lvi As ListViewItem In myListView.Items
If lvi.Text = searchString Then
Return True
Else
For Each lviSub As ListViewItem.ListViewSubItem In lvi.SubItems
If lviSub.Text = searchString Then
Return True
End If
Next
End If
Next
Return False
End Function

Cheers

Arne Janning
 
dim i as integer

i = myListViewName.Items.IndexOf(myText)

I will return the index if myText is found and -1 if not
 
Thanks for your reply.
I thought there's a function that allow us to do so.
But seems like we have to create our own. Which is good as well.

Thanks.
 
You might try something like this:

Dim i As Integer
Dim c As ListViewItem.ListViewSubItem = new ListViewItem.ListViewSubItem
c.Text = mysubitemtext
i = myListView.Items.IndexOf(myitemtext)
Dim k As ListViewItem = CType(myListView.Items.Item(i), ListViewItem)
i = k.SubItems.IndexOf(c)

i should return the sub index number of the subitem if found or -1 if not
found.

I haven't tried it so it might not work but it does compile. Also, there's
probably a shorter way to do this if one played around with it. I don't know
why M'soft didn't allow searching for strings directly in subitems as they do
in items. I guess it's part of job security for professional programmers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top