【问题标题】:How to take only first index from combobox c#如何仅从组合框 c# 中获取第一个索引
【发布时间】:2021-01-04 08:37:17
【问题描述】:

我的组合框上有两个索引。

我只想取第一个索引?

我可以举一些例子吗?

代码:

              foreach (DataRow dr2 in dt2.Rows)
            {
                comboBox1.Items.Add(dr2["Station"].ToString() + " - " + dr2["Ime"].ToString());
            }

我要拍dr2["Station"].ToString()

【问题讨论】:

    标签: c# windows visual-studio windows-forms-designer


    【解决方案1】:

    Win Forms ComboBox 具有 SelectedIndexSelectedText 属性。

    一旦您的列表加载了项目,您就可以像这样选择要选择的项目:

    // selected by position in the list
    comboBox1.SelectedIndex = 0;
    
    // ... by value
    comboBox1.SelectedText = "some value";
    

    【讨论】:

      猜你喜欢
      • 2021-01-05
      • 1970-01-01
      • 2016-05-07
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      • 1970-01-01
      • 2018-05-02
      • 2018-06-06
      相关资源
      最近更新 更多