【问题标题】:How to add value dynamically in a combo box in windows application [duplicate]如何在Windows应用程序的组合框中动态添加值[重复]
【发布时间】:2014-07-06 23:53:55
【问题描述】:

我有一个两个组合框。我想将第一个组合框中未选择的值动态添加到第二个组合框。

【问题讨论】:

  • 那么问题出在哪里? (提示,使用几个临时列表)
  • 只使用selection changed事件,获取combo box中的所有item,去掉那些被选中的

标签: c#


【解决方案1】:
Dictionary<string, string>test = new Dictionary<string, string>();
        test.Add("1", "dfdfdf");
        test.Add("2", "dfdfdf");
        test.Add("3", "dfdfdf");
        comboBox1.DataSource = new BindingSource(test, null);
        comboBox1.DisplayMember = "Value";
        comboBox1.ValueMember = "Key";

// Get combobox selection (in handler)
string value = ((KeyValuePair<string, string>)comboBox1.SelectedItem).Value;

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2012-12-31
  • 2023-03-27
  • 1970-01-01
  • 2011-08-26
  • 2017-08-26
  • 2015-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多