For Each Loop Problem

obscuregirl

Member
Joined
Sep 13, 2006
Messages
15
Location
UK
Programming Experience
Beginner
Hi

I'm trying to use a For Each loop to iterate through a collection of items from a combobox and compare the value of each item in the collection to a string value to find the index of the string value in the combobox and then set another combobox's .selectedIndex to that index. But instead of comparing the two values, my code seems to be setting the value of the first item in the collection to the value of the item it is supposed to be being compared to! Help!

VB.NET:
If selID IsNot""Then
comboColl = coPropID.Items()
ForEach thisObject AsStringIn comboColl
If thisObject = selID Then
ind = coPropID.Items.IndexOf(selID)
ExitFor
EndIf
Next thisObject
coProp.SelectedIndex = ind
EndIf
 
Last edited by a moderator:
Sorted!

I had this question on another forum too and a very kind person gave me the answer, so here it is incase anyone else is having a similar problem!

You wont need a loop,
'assuming coPropID is the combobox holding the items to be searched
'and coProp is the combobox to be selected
coProp.SelectedIndex = coPropID.FindStringExact(selID)

 
Back
Top