【问题标题】:how to get selected value from combox in windows c#如何从Windows C#的组合框中获取选定的值
【发布时间】:2015-03-21 15:19:52
【问题描述】:

我是 Windows 新手。我想在 Windows C# 的组合框中更改索引上的选定项目,在页面加载时它调用 selectedindexchanged 事件。它是如何发生的。所以请帮帮我。

提前致谢

【问题讨论】:

  • 什么页面加载?你说的是 ASP.NET 吗?

标签: c# window


【解决方案1】:

这是一个简单的例子:

int selectedIndex = comboBox1.SelectedIndex;
Object selectedItem = comboBox1.SelectedItem;

MessageBox.Show("Selected Item Text: " + selectedItem.ToString() + "\n" +
                "Index: " + selectedIndex.ToString());

【讨论】:

    【解决方案2】:

    假设你在 SelectedIndexChanged 事件中:

            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                MessageBox.Show("Selected Item Text: " + comboBox1.SelectedItem.ToString() + "\n" +
                                "Index: " + comboBox1.SelectedIndex.ToString());
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多