Results 1 to 4 of 4

Thread: Searching ListView2 for string and removing

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    27

    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 2011
    Posts
    9,017

    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 | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    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

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    27

    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

    Thread Starter
    Junior Member
    Join Date
    May 2012
    Posts
    27

    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
  •  



Click Here to Expand Forum to Full Width