简体   繁体   English

ComboBox.SelectedItem发行C#

[英]ComboBox.SelectedItem Issue C#

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. 问题是,当我将项目加载到组合框中并以编程方式更改selectedIndex或selectedItem时,它不起作用。 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. 例如,如果我将selectedIndex分配给第一项,则comboBox不会通过if语句传递给我,该语句将检查selectedIndex是否为-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. 是否有人对如何以编程方式将selectedIndex或selectedeItem分配给同时也以编程方式添加了项目的comboBox的任何建议,以便在这种情况下可以正常工作。 Thanks 谢谢

XmlNode trialNumber = doc.SelectSingleNode(pathString + "/trial");
selectTrialNumberComboBox.SelectedItem = trialNumber.InnerText.ToString();
selectTrialNumber = trialNumber.InnerText.ToString();
selectTrialNumberComboBox.Enabled = false;

采用

selectTrialNumberComboBox.SelectedIndex = selectTrialNumberComboBox.Items.IndexOf(selectTrialNumberComboBox.Items.FindByText(trialNumber.InnerText.ToString())) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM