[Help]ListView Searching

Posts 1–3 of 3 · Page 1 of 1
[Help]ListView Searching
Hello guys!

I have this code:

Code:
ListView1.MultiSelect = True
        ListView1.SelectedItems.Clear()
            Dim itm As ListViewItem

            With ListView1
                itm = .FindItemWithText(TextBox4.Text, True, 0, True)
                If Not itm Is Nothing Then

                    For i = 0 To ListView1.Items.Count - 1
                        .Items.Item(itm.Index).Selected = True
                    Next i

                    itm = Nothing

                End If
            End With
but this code only select one item. I want to make code which will select multiply items!


Thanks for help!
Are you trying to select everything in listview?
Quote Originally Posted by NeRd.? View Post
Hello guys!

I have this code:

Code:
ListView1.MultiSelect = True
        ListView1.SelectedItems.Clear()
            Dim itm As ListViewItem

            With ListView1
                itm = .FindItemWithText(TextBox4.Text, True, 0, True)
                If Not itm Is Nothing Then

                    For i = 0 To ListView1.Items.Count - 1
                        .Items.Item(itm.Index).Selected = True
                    Next i

                    itm = Nothing

                End If
            End With
but this code only select one item. I want to make code which will select multiply items!


Thanks for help!
There is a logic problem on that code, index is a unique property. As far as I can see, you are only getting one index from the first item you find that has the text from the textbox.

So its pointless to select every items with that index because there is only ONE for sure. (useless FOR, its repeating exactly the same every single loop)

New Logic:

Code:
Loop
      Check If the current item has the text you want
               If yes, select
Dont forget about the multiselect property of the control
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?