Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
int item = ComboBox.FindStringExact("Open"); if (item >= 0) ComboBox.SelectedItem = item;
我想(以编程方式)将组合框中的项目选择为显示打开的项目
我的代码不起作用,但我将不胜感激
我相信你想要SelectedIndex而不是SelectedItem(我在这里假设 item >= 0)。
SelectedIndex
SelectedItem
item >= 0
从你所说的听起来你想要
ComboBox.SelectedIndex = item;
但是,我建议通过以下方式坚持使用 SelectedItem:
ComboBox.SelectedItem = "Open"; //use the exact string that is used in the combobox.