[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
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.
Re: Find Items CheckedListBox - StringArray -looking for better solution
Thanks cicatrix, thats was the reason ;-) for more neater code