Reputation: 703
I have an application in which I am allowing a user to load the selections they previously made in a form and then allowing them to save changes. The problem is that when I load items into a combobox and change the selectedIndex or selectedItem programmatically it is not working. For exacmple if I assign the selectedIndex to the first item that comboBox will not pass through an if statement I have that checks if the selectedIndex is -1. Does anyone have any suggestions on how to programmatically assign a selectedIndex or selectedeItem to a comboBox in which the items were also programmatically added so that it will work in this situation. Thanks
XmlNode trialNumber = doc.SelectSingleNode(pathString + "/trial");
selectTrialNumberComboBox.SelectedItem = trialNumber.InnerText.ToString();
selectTrialNumber = trialNumber.InnerText.ToString();
selectTrialNumberComboBox.Enabled = false;
Upvotes: 0
Views: 878
Reputation: 1838
Use
selectTrialNumberComboBox.SelectedIndex = selectTrialNumberComboBox.Items.IndexOf(selectTrialNumberComboBox.Items.FindByText(trialNumber.InnerText.ToString()))
Upvotes: 1