Results 1 to 4 of 4

Thread: Searching ListView2 for string and removing

  1. #1
    Junior Member
    Join Date
    May 12
    Posts
    22

    Searching ListView2 for string and removing

    Trying to figure out how to find the text that is typed in "SeedKW text" and when Cmd button i clicked, it removes that text from "SeedKW text" from listview2

    vb Code:
    1. Dim srt As String = "Searches related to " & SeedKW.Text
    2.         For Each srtItem As ListViewItem In ListView2.Items
    3.             If srtItem.SubItems.Item(0).Text = srt Then
    4.                 MsgBox(srt)
    5.             End If
    6.         Next

    I Would like to have it search for a partial string like and removing everything from listview one that contains "Searches related to" is that's possible.

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 11
    Posts
    3,143

    Re: Searching ListView2 for string and removing

    Strings have a StartsWith method that you could use to identify partial strings:-
    vbnet Code:
    1. '
    2.         Dim strn As String = "ABC 123"
    3.  
    4.         If strn.StartsWith("ABC") Then MsgBox("YES!!!")
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | Create Sortable BindingList(not mine) | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  3. #3
    Junior Member
    Join Date
    May 12
    Posts
    22

    Re: Searching ListView2 for string and removing

    Quote Originally Posted by Niya View Post
    Strings have a StartsWith method that you could use to identify partial strings:-
    vbnet Code:
    1. '
    2.         Dim strn As String = "ABC 123"
    3.  
    4.         If strn.StartsWith("ABC") Then MsgBox("YES!!!")


    Thank you, this is what i came up with from your code.

    VB.NET Code:
    1. For Each srt As ListViewItem In ListView2.Items
    2.             If srt.SubItems(0).Text.StartsWith("Searches related to") Then
    3.                 ListView2.Items.Remove(srt)
    4.             End If
    5.         Next

  4. #4
    Junior Member
    Join Date
    May 12
    Posts
    22

    Re: Searching ListView2 for string and removing

    Quote Originally Posted by Niya View Post
    Strings have a StartsWith method that you could use to identify partial strings:-
    vbnet Code:
    1. '
    2.         Dim strn As String = "ABC 123"
    3.  
    4.         If strn.StartsWith("ABC") Then MsgBox("YES!!!")


    Thank you, this is what i came up with

    VB.NET Code:
    1. For Each srt As ListViewItem In ListView2.Items
    2.             If srt.SubItems(0).Text.StartsWith("Searches related to") Then
    3.                 ListView2.Items.Remove(srt)
    4.             End If
    5.         Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •