日期:2014-05-18  浏览次数:20907 次

关于combobox绑定的问题
我想对三个combobox绑定同一张表,但相互之间不会同时改变  
但是下面这段代码的结果是 两个combobox一起变,不是相互独立的,一改就一起变..... 到底要怎么写啊?

PDMSDataSet pDMSDataSet = new PDMSDataSet();
  PDMSDataSetTableAdapters.HospitalTableAdapter adapter = new PDMS.PDMSDataSetTableAdapters.HospitalTableAdapter();
  adapter.Fill(this.pDMSDataSet.Hospital);
  BindingSource bindinSource = new BindingSource();
  bindinSource.DataSource = this.pDMSDataSet;
  bindinSource.DataMember = "Hospital";
  Fircombo.DataSource = bindinSource;
  Fircombo.DisplayMember = "Hname";
  Fircombo.ValueMember = "Hid";

  Seccombo.DataSource = bindinSource;
  Seccombo.DisplayMember = "Hname";
  Seccombo.ValueMember = "Hid";

------解决方案--------------------
三个 Combobox 指定不同的 BindingSource
C# code
PDMSDataSet pDMSDataSet = new PDMSDataSet();
PDMSDataSetTableAdapters.HospitalTableAdapter adapter = new PDMS.PDMSDataSetTableAdapters.HospitalTableAdapter();
adapter.Fill(this.pDMSDataSet.Hospital);

Fircombo.DataSource = new BindingSource(pDMSDataSet, "Hname");
Fircombo.DisplayMember = "Hname";
Fircombo.ValueMember = "Hid";

Seccombo.DataSource = new BindingSource(pDMSDataSet, "Hname");
Seccombo.DisplayMember = "Hname";
Seccombo.ValueMember = "Hid";

------解决方案--------------------
拷贝3份dataset。每份绑定一个combobox