I have a variable which contains a value such as
-9
i have 21 items in the combo box and their contents set to from -10 to +10.
i want to programmatically select the combobox item based on the variable…
i been looking for some sort of reference or solution but cannot find one…
myVar = "-9";
myCB.selectedValue = myVar.ToString();
the above code doesn’t give any error but the combobox displays with a blank value… all other values are there (-10 to +10) but none of them are selected….
sorry if the question is too stupid…. but i am learning to code for windows 8 apps using c#
please help.
thanks
The 21 items in you combobox are selectable by using the indexes of 0 to 20. Your code above shows you are trying to set the value to -9 which does not exist and you are trying to set it with a string of -9 (will fail unless the value is -9 and you use SelectedItem). You should really be using SelectedIndex or SelectedItem instead of SelectedValue.
Put some smarts in your code before setting combobox. eg -9 would be 1. Hope this helps!