private void Form1_Load(object sender, EventArgs e)
        {
            
            string sql = "select Id,CityName from CityInfo";
            SqlConnection conn = new SqlConnection(dbstr);
            
            conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
            DataSet ds = new DataSet();
            sda.Fill(ds, "city");
            comboBox1.DataSource = ds.Tables["city"];
            comboBox2.DataSource = ds.Tables["city"];            comboBox1.DisplayMember = "CityName";
            comboBox1.ValueMember = "Id";
            comboBox2.DisplayMember = "CityName";
            comboBox2.ValueMember = "Id";            conn.Close();
        }以上是代码、问题是当我选择  comboBox1  里的数据时、 comboBox2  的数据会同时跟着改变、变成跟 comboBox1 里的数据一样了,并且  comboBox2  改变时  comboBox1  也会跟着变
这是问题抓图

解决方案 »

  1.   

    你绑定的都是同一个数据table,当然一样了
      

  2.   


    建过了、那种情况导致comboBox2的数据加载不了了、不知道怎么回事、现在解决了、我把另外个comboBox数据加载放到了groupbox里去了、
      

  3.   

    comboBox好像有个selectChange事件(记不清了 就是选项发生变化触发的那个事件)。。
    在这个事件里面写赋值就可以了,不过我好像记得,只有提前加载过的项才可以赋值成功