Question

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;
Was it helpful?

Solution

Use

selectTrialNumberComboBox.SelectedIndex = selectTrialNumberComboBox.Items.IndexOf(selectTrialNumberComboBox.Items.FindByText(trialNumber.InnerText.ToString())) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top