如何在Windows应用程序的组合框中动态添加值

时间:2014-05-19 06:03:40

标签: c#

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

1 个答案:

答案 0 :(得分:-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;