I have a ComboBox with 3 hardcoded string values:
A
B
C
If I try to change the currently selected value based on SelectedValue, SelectedItem, or SelectedText, neither of them change the index to the proper item.
Currently I’m doing something like:
switch (str)
{
case 'A':
comboBox.SelectedIndex = 0;
break;
case 'B':
comboBox.SelectedIndex = 1;
break;
case 'C':
comboBox.SelectedIndex = 2;
break;
}
But as you can see it’s a rather weak solution and will break if items are re-ordered, edited, or appended.
Any better ways?
You can do this:
but this also works on my computer:
There must be a problem with your strings that are hardcoded in the comboBox. Check if there are some unusual characters or white (blank) characters.