【发布时间】:2014-02-17 17:39:42
【问题描述】:
在 VS 2010 中,我创建了一个数据绑定表单,方法是从数据源窗口拖动到一个空表单。数据源(类型化数据集)有两列:CustomerCode 和 CustomerName。在表单的 Load 事件中我写道:
private void SalesInvoiceForm_Load(object sender, EventArgs e)
{
//Populate customer code combobox
var customerTableAdapter = new companyDataSetTableAdapters.CustomerTableAdapter();
customerTableAdapter.Fill(this.companyDataSet.Customer);
customerCodeComboBox.DataSource = this.companyDataSet.Customer;
customerCodeComboBox.ValueMember = "Code";
customerCodeComboBox.DisplayMember = "Code";
//Populate customer name combobox
//customerNameComboBox.DataSource = this.companyDataSet.Customer;
customerNameComboBox.ValueMember = "Name";
customerNameComboBox.DisplayMember = "Name";
this.salesInvoiceTableAdapter.Fill(this.companyDataSet.SalesInvoice);
}
不知何故,当我从 customerCodeComboBox 中选择客户代码时,customerNameComboBox 会自动同步,即显示所选客户的姓名。 customerNameComboBox 也是如此。最初我认为我需要为每个组合框的 SelectedIndexChanged 事件处理程序编写一个代码,两个同步它们。为什么这会自动发生?因为他们的 DataSource 属性设置为相同的数据表?我认为数据表没有任何与位置相关的功能。
【问题讨论】: