【问题标题】:I need help programatically changing my combobox in WinForms我需要帮助以编程方式更改 WinForms 中的组合框
【发布时间】:2012-04-28 04:47:42
【问题描述】:
int item = ComboBox.FindStringExact("Open"); 
    if (item >= 0) 
        ComboBox.SelectedItem = item;

我想(以编程方式)将我的组合框中的项目选择为打开的项目

我的代码不起作用,但我会很感激任何帮助

【问题讨论】:

  • 地铁?表格? WPF?银光? ASP.NET?单触?
  • 您遇到什么错误?这是 Windows 窗体吗? WPF?还有什么?
  • item >= 0?另外,字符串大小写是否正确?
  • 如果您使用的是WinForms,请添加相应的标签。

标签: c# winforms c#-4.0 combobox


【解决方案1】:

我相信你想要SelectedIndex 而不是SelectedItem(我假设 item >= 0 这里)。

【讨论】:

    【解决方案2】:

    从你所说的听起来像是你想要的

    ComboBox.SelectedIndex = item;
    

    但是,我建议通过以下方式坚持使用 SelectedItem:

    ComboBox.SelectedItem = "Open";  
    //use the exact string that is used in the combobox.
    

    【讨论】:

    • 大声笑。甚至没有注意到我这样做了。
    猜你喜欢
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-12
    • 2020-10-13
    • 2011-06-17
    • 1970-01-01
    • 2011-10-04
    相关资源
    最近更新 更多