How bizarre! For the benefit of anyone else reading this, with a breakpoint on the line
if (lbxcityTours.SelectedItem.ToString() == t1)
examining the value of
lbxcityTours.SelectedIndex
gives 0 for all values of
i
I have no idea why that is happening, but I managed to stop it from misbehaving by ensuring nothing was selected at all before assigning to the SelectedIndex - i.e.
lbxcityTours.SelectedIndex = -1;
lbxcityTours.SelectedIndex = i;
Perhaps it's telling that Microsoft do not give an example of setting this value in the documentation, only getting it.