Results 1 to 3 of 3

Thread: [RESOLVED] Find Items CheckedListBox - StringArray -looking for better solution

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Resolved [RESOLVED] Find Items CheckedListBox - StringArray -looking for better solution

    Greetings,

    I have a CheckedListBox with Items
    I also have a Stringarray which contains values from a DB

    All Items in the CheckedListBox ar checked, now i like to uncheck all items if there are in the StringArray.

    Normaly i would do 2 for loops like

    Code is only pseudo - so no need to say it would not work this way
    I know

    Code:
    ' Loop though CheckedListBox
    For i = 0 to CheckedListBox.count -1
    
       ' Loop though StrArray
       For ii = 0 to Ubound(strArray)
    
          ' Compair CheckListBoxItem against StrArray Item
          ' and check / uncheck depending of result
    
       Next ii
    Next i
    I am now wondering if there is a better or more efficient way to do this, not through looping in a worst case scenario 200 * 200 times.

    Thanks for your input

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Find Items CheckedListBox - StringArray -looking for better solution

    It is a somewhat better way but only if you use List(Of String) collection instead of array.
    List collection has .Contains method that returns true if the argument is found in the collection and false if it doesn't.
    Technically, it would be the same for...next loop in the background but the code will be neater and without nested loops.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: Find Items CheckedListBox - StringArray -looking for better solution

    Thanks cicatrix, thats was the reason ;-) for more neater code

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