C# – Why changing SelectedItem in one Combo changes all other Combos

ccomboboxwinforms

I populated comboboxes in this way

foreach (Control c in this.Controls)
{
     if (c is ComboBox)
     {
         (c as ComboBox).DataSource = DataSet1.Tables[0];
         (c as ComboBox).DisplayMember = "Articles";
     }
}

But, problem is when I change SelectedItem in one Combo – it becomes changed in all other Combos?

Best Answer

Bind them each to a separate instance of the DataSet1.Table[0].

ie)

foreach (Control c in this.Controls)
{
    if (c is ComboBox)
    {
        DataTable dtTemp = DataSet1.Tables[0].Copy();
        (c as ComboBox).DataSource = dtTemp 
        (c as ComboBox).DisplayMember = "Articles";
    }
}