将一个List <t>绑定到多个下拉列表</t>

时间:2014-11-25 16:58:34

标签: c# winforms binding

我有一个简单的WinForm,一个CR报告和一个允许用户将参数传递给Crystal Report的类。

向用户显示2个选项以控制报告中显示的内容。

WinForm:
Customer ID: [dropdownlist1] to [dropdownlist2]
Customer Name: [dropdownlist3] to [dropdownlist4]
[OK][Cancel]

基本上,上述WinForm允许用户从A到Z中选择一系列客户ID和/或名称。

我连接到数据库并使用List.Add(new Customer(id,name))来获取客户数据库返回的所有固定的200条记录(客户数据库表是固定的,不会根据我们的用户增长)表

在我的代码中,

var customer1 = new Customer();

//Do DB connection and loop through the record and add to List<T>
//List<Customer>.Add(new Customer(reader.GetInt16(0), reader.GetString(1)));

dropdownlist1.ValueMember = "customerID";
dropdownlist1.DisplayMember = "customerID";
dropdownlist1.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

dropdownlist2.ValueMember = "customerID";
dropdownlist2.DisplayMember = "customerID";
dropdownlist2.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

dropdownlist3.ValueMember = "customerName";
dropdownlist3.DisplayMember = "customerName";
dropdownlist3.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

dropdownlist4.ValueMember = "customerName";
dropdownlist4.DisplayMember = "customerName";
dropdownlist4.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

我遇到的问题是,在加载WinForm之后,每当我在dropdownlist1中进行选择更改时,所有剩余的3个下拉列表将更改为我在dropdownlist1中选择的那个。这与我做出的其他列表选择情况相同。

发生什么事了?除非我在每个下拉列表中进行了更改,否则如何使单个列表单独运行?

0 个答案:

没有答案
相关问题