C# 将两个组合框绑定到同一数据源,使每个组合都有各自的行为

C# 将两个组合框绑定到同一数据源,使每个组合都有各自的行为,c#,winforms,binding,combobox,C#,Winforms,Binding,Combobox,现在,当我在第一个组合框中选择项时,第二个组合框将模拟选择。 我希望能够在每个组合框中分别进行选择。 谢谢 List TaskStatus=W6AdminUIs2.GlobalFunctions.GetDictionaryItems(“TaskStatus”); //初始化状态的绑定源。 BindingSource bsFromStatuses=新BindingSource(); bsFromStatuses.DataSource=任务状态; //将“From”组合框绑定到绑定源。 cBoxFr

现在,当我在第一个组合框中选择项时,第二个组合框将模拟选择。 我希望能够在每个组合框中分别进行选择。 谢谢

List TaskStatus=W6AdminUIs2.GlobalFunctions.GetDictionaryItems(“TaskStatus”);
//初始化状态的绑定源。
BindingSource bsFromStatuses=新BindingSource();
bsFromStatuses.DataSource=任务状态;
//将“From”组合框绑定到绑定源。
cBoxFrom.DataSource=bsFromStatuses.DataSource;
cBoxFrom.DisplayMember=“Name”;
cBoxFrom.ValueMember=“Key”;
//初始化状态的绑定源。
BindingSource BStatuses=新的BindingSource();
bsstatuses.DataSource=任务状态;
//将“From”组合框绑定到绑定源。
cBoxTo.DataSource=bstatuses.DataSource;
cBoxTo.DisplayMember=“Name”;
cBoxTo.ValueMember=“Key”;

我不知道您使用的是哪种词典,但我使用的是普通词典,并且此代码的行为与此不同:

Dictionary<string,string> dict = new Dictionary<string, string>();
dict.Add("S1", "Sample1");
dict.Add("S2", "Sample2");
dict.Add("S3", "Sample3");
dict.Add("S4", "Sample4");

comboBox1.DataSource = new BindingSource(dict, null);
comboBox1.DisplayMember = "value";
comboBox1.ValueMember = "key";

comboBox2.DataSource = new BindingSource(dict, null);
comboBox2.DisplayMember = "value";
comboBox2.ValueMember = "key";
Dictionary dict=new Dictionary();
添加(“S1”、“样本1”);
添加(“S2”、“样本2”);
添加(“S3”、“样本3”);
添加(“S4”、“样本4”);
comboBox1.DataSource=新的BindingSource(dict,null);
comboBox1.DisplayMember=“值”;
comboBox1.ValueMember=“key”;
comboBox2.DataSource=新的BindingSource(dict,null);
comboBox2.DisplayMember=“值”;
comboBox2.ValueMember=“key”;

我不知道您使用的是哪种词典,但我使用的是普通词典,并且此代码的行为与此不同:

Dictionary<string,string> dict = new Dictionary<string, string>();
dict.Add("S1", "Sample1");
dict.Add("S2", "Sample2");
dict.Add("S3", "Sample3");
dict.Add("S4", "Sample4");

comboBox1.DataSource = new BindingSource(dict, null);
comboBox1.DisplayMember = "value";
comboBox1.ValueMember = "key";

comboBox2.DataSource = new BindingSource(dict, null);
comboBox2.DisplayMember = "value";
comboBox2.ValueMember = "key";
Dictionary dict=new Dictionary();
添加(“S1”、“样本1”);
添加(“S2”、“样本2”);
添加(“S3”、“样本3”);
添加(“S4”、“样本4”);
comboBox1.DataSource=新的BindingSource(dict,null);
comboBox1.DisplayMember=“值”;
comboBox1.ValueMember=“key”;
comboBox2.DataSource=新的BindingSource(dict,null);
comboBox2.DisplayMember=“值”;
comboBox2.ValueMember=“key”;

正是我需要的正是我需要的