obscuregirl
Member
Hi
I'm having some problems with a For Each loop and wondered if anyone could help.
I have a combo box (coPropID) on my screen that has been preloaded with the IDs of all people in my database. I have another combo called coProp that has been preloaded with the names of all the people on the database in the same order, so that index 0 of coPropID contains the ID for the person whose name appears in the index 0 of coProp. When this screen is loaded to show an existing record, I retrieve the person's ID from the database and want to be able to use it to find the name in the coProp combobox.
I'm using a For Each loop to find the id retrieved from the database (which has been assigned to a string called supStr) and find the index within the combobox that this ID sits on. I then want to set the index of the coProp combobox to that index and display the name.
However, it is not working. I have tried to step through it, but it appears to look at the first item in the combo, not finding a match and not looping through to any of the other items. My code appears below:
I'm having some problems with a For Each loop and wondered if anyone could help.
I have a combo box (coPropID) on my screen that has been preloaded with the IDs of all people in my database. I have another combo called coProp that has been preloaded with the names of all the people on the database in the same order, so that index 0 of coPropID contains the ID for the person whose name appears in the index 0 of coProp. When this screen is loaded to show an existing record, I retrieve the person's ID from the database and want to be able to use it to find the name in the coProp combobox.
I'm using a For Each loop to find the id retrieved from the database (which has been assigned to a string called supStr) and find the index within the combobox that this ID sits on. I then want to set the index of the coProp combobox to that index and display the name.
However, it is not working. I have tried to step through it, but it appears to look at the first item in the combo, not finding a match and not looping through to any of the other items. My code appears below:
VB.NET:
If supStr IsNot "" Then
comboColl = coPropID.Items()
For Each thisObject As String In comboColl
If thisObject <> supStr Then
'go to next thisObject
Else
ind = coPropID.Items.IndexOf(supStr)
Exit For
End If
Next thisObject
coProp.SelectedIndex = ind
End If