Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I bind two controls to the same DataTable without having changes in one control also change the other control?

When I try to bind two ComboBoxes to the same DataTable, both ComboBoxes show the same values, changing one changes the other. How do I make them have distinct values?

Use different BindngContext objects for the two ComboBoxes as shown here.

comboBox1.BindingContext = new BindingContext();
comboBox1.DataSource = dataset.Tables[ "Orders" ];
comboBox1.ValueMember = "CustomerID";
comboBox1.DisplayMember = "CustomerID";

comboBox2.BindingContext = new BindingContext();
comboBox2.DataSource = dataset.Tables[ "Orders" ];
comboBox2.ValueMember = "CustomerID";
comboBox2.DisplayMember = "CustomerID";

Contributed from George Shepherd's Windows Forms FAQ



Page view counter