日期:2014-05-19  浏览次数:20871 次

高手进,多个comboBox绑定一个dataset问题
comboBox1.DisplayMember   =   "codename ";
comboBox1.ValueMember   =   "codeno ";
comboBox1.DataSource   =   ds.Tables[0];

comboBox2.DisplayMember   =   "codename ";
comboBox2.ValueMember   =   "codeno ";
comboBox2.DataSource   =   ds.Tables[0];

可是当我下拉任何一个comboBox后,另外的comboBox的text也都定位到了下拉的text。请问怎么处理??

------解决方案--------------------
Fill到不同的表,分别绑定

da.Fill(ds, "test1 ");
da.Fill(ds, "test2 ");

comboBox1.DisplayMember = "codename ";
comboBox1.ValueMember = "codeno ";
comboBox1.DataSource = ds.Tables[ "test1 "];

comboBox2.DisplayMember = "codename ";
comboBox2.ValueMember = "codeno ";
comboBox2.DataSource = ds.Tables[ "test2 "];
------解决方案--------------------
那就创建多个DataSet实例,分别绑定

DataSet ds1 = GetDataSet(); //GetDataSet()为你的返回DataSet的方法
DataSet ds2 = GetDataSet();

comboBox1.DisplayMember = "codename ";
comboBox1.ValueMember = "codeno ";
comboBox1.DataSource = ds1.Tables[ "test1 "];

comboBox2.DisplayMember = "codename ";
comboBox2.ValueMember = "codeno ";
comboBox2.DataSource = ds2.Tables[ "test2 "];

------解决方案--------------------
DataSet ds1 = GetDataSet(); //GetDataSet()为你的返回DataSet的方法
DataSet ds2 = GetDataSet();

comboBox1.DisplayMember = "codename ";
comboBox1.ValueMember = "codeno ";
comboBox1.DataSource = ds1.Tables[0]; //这里忘改了

comboBox2.DisplayMember = "codename ";
comboBox2.ValueMember = "codeno ";
comboBox2.DataSource = ds2.Tables[0];
------解决方案--------------------
DataTable dt = new DataTable();
dt = ds.Tables[0].Copy();

this.comboBox2.DataSource = dt;
this.comboBox2.DisplayMember = "id ";