2014-01-27 21 views
0

在VS 2010中,我通过从数据源窗口拖动到空表单创建了一个数据绑定表单。数据源(输入数据集)有两列:CustomerCode和CustomerName。在窗体的Load事件中,我写道:Windows窗体组合框自动同步;为什么?

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属性被设置为相同的数据表?我认为datatable没有任何位置相关的功能。

回答

0

为什么会自动发生这种情况?因为他们的DataSource属性被设置为相同的数据表?

我以为DataTable中没有任何位置相关的功能。

它不;但绑定系统在幕后使用CurrencyManager,它处理当前项目的概念。

+0

但是,表单没有customerBindingSource。尽管它有salesInvoiceBindingSource。此外,我注意到,DataGridView中的comboxboxes也不起作用。你能解释一下吗? – synergetic