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

本文关键字:动态 添加 组合 windows 应用程序 | 更新日期: 2023-09-27 18:03:53

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

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

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;