Combobox Data Binding(自主选择)
Combobox Data Binding (independent choice)
我像这样在两个不同的组合框中绑定一些数据:
BindingList<Customer> customers = new BindingList<Customer>();
customer.Add(new Customer(1, "Mike"));
customer.Add(new Customer(2, "Max"));
customer.Add(new Customer(3, "Taylor"));
combobox1.DisplayMember = "Name";
combobox1.ValueMember = "Id";
combobox1.DataSource = customers;
combobox2.DisplayMember = "Name";
combobox2.ValueMember = "Id";
combobox2.DataSource = customers;
它运行良好,但如果我 select 在 combobox1 中添加某些项目,则此项目会自动 select 在 combobox2 中。如何解决这个问题(需要自主选择)?
下面的代码对我来说是无缝的:
BindingList<Customer> customer = new BindingList<Customer>();
customer.Add(new Customer(1, "Mike"));
customer.Add(new Customer(2, "Max"));
customer.Add(new Customer(3, "Taylor"));
BindingList<Customer> customer2 = new BindingList<Customer>(customer);
combobox1.DisplayMember = "Name";
combobox1.ValueMember = "Id";
combobox1.DataSource = customer;
combobox2.DisplayMember = "Name";
combobox2.ValueMember = "Id";
combobox2.DataSource = customer2;
我像这样在两个不同的组合框中绑定一些数据:
BindingList<Customer> customers = new BindingList<Customer>();
customer.Add(new Customer(1, "Mike"));
customer.Add(new Customer(2, "Max"));
customer.Add(new Customer(3, "Taylor"));
combobox1.DisplayMember = "Name";
combobox1.ValueMember = "Id";
combobox1.DataSource = customers;
combobox2.DisplayMember = "Name";
combobox2.ValueMember = "Id";
combobox2.DataSource = customers;
它运行良好,但如果我 select 在 combobox1 中添加某些项目,则此项目会自动 select 在 combobox2 中。如何解决这个问题(需要自主选择)?
下面的代码对我来说是无缝的:
BindingList<Customer> customer = new BindingList<Customer>();
customer.Add(new Customer(1, "Mike"));
customer.Add(new Customer(2, "Max"));
customer.Add(new Customer(3, "Taylor"));
BindingList<Customer> customer2 = new BindingList<Customer>(customer);
combobox1.DisplayMember = "Name";
combobox1.ValueMember = "Id";
combobox1.DataSource = customer;
combobox2.DisplayMember = "Name";
combobox2.ValueMember = "Id";
combobox2.DataSource = customer2;