Results 1 to 6 of 6

Thread: [RESOLVED] CheckedListBox.Remove (*wildcard) or For each..

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    11

    Resolved [RESOLVED] CheckedListBox.Remove (*wildcard) or For each..

    Ive searched high and low and can not come up with a solution..maybe Im just using the wrong search string...any help would be great. Basically I have read a txt file line by line split with regex all works well except blank space so I .remove("") blank line. Now I need to further remove all strings that start with prefix of PREFIX_somefile. Thanks for any help!


    Code:
    Dim str As String
                For Each str In strs
                    CheckedListBox1.Items.Add(str)
                    CheckedListBox1.Sorted = True
                    CheckedListBox1.Items.Remove("")
                    CheckedListBox1.Items.Remove("PREFIX_"*wildcard)
                Next
    Last edited by bbdevel; Jul 9th, 2009 at 05:44 PM.

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: CheckedListBox.Remove (*wildcard) or For each..

    Just use the str.contains("PREFIX_") to compare and remove that line...

    The code
    VB.NET Code:
    1. Dim str As String
    2.         For Each str In strs
    3.             If str.Contains("PREFIX_") OrElse str.Length = 0 Then
    4.                 Continue For
    5.             End If
    6.             CheckedListBox1.Items.Add(str)
    7.             CheckedListBox1.Sorted = True
    8.         Next
    Last edited by mickey_pt; Jul 9th, 2009 at 05:56 PM. Reason: Code...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    11

    Re: CheckedListBox.Remove (*wildcard) or For each..

    Code:
    Dim itemText As String
    
                    For i As Integer = (CheckedListBox1.Items.Count - 1) To 0 Step -1
                        itemText = CheckedListBox1.GetItemText(CheckedListBox1.Items(i))
                        If itemText.StartsWith("PREFIX_") Then
                            CheckedListBox1.Items.RemoveAt(i)
                        End If
                    Next
    This works perfect do you recommend this code? Would your way be easier? Thanks for your reply tho
    Last edited by bbdevel; Aug 3rd, 2009 at 12:23 AM.

  4. #4
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: CheckedListBox.Remove (*wildcard) or For each..

    Why do you add, and then remove?

    I think it's better to remove before add...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    11

    Re: CheckedListBox.Remove (*wildcard) or For each..

    Quote Originally Posted by mickey_pt View Post
    Why do you add, and then remove?

    I think it's better to remove before add...
    I think your right too! Thanks for your help! Your code works too! Wouldn't know how to make a function key for app with no button? Giving rep and marking resolved.

  6. #6
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: [RESOLVED] CheckedListBox.Remove (*wildcard) or For each..

    Thanks

    But i don't understand what you trying to do, and if this is another question just create a new thread and mark this one resolved.

    Rate People That Helped You
    Mark Thread Resolved When Resolved

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