I have the following code to populate 3 comboboxes:
private void PopulateDDLs()
{
SqlConnection connection;
SqlCommand command;
SqlDataReader reader;
DataTable dt;
using (connection = new SqlConnection("connection string here"))
{
using (command = new SqlCommand("sql query here", connection))
{
connection.Open();
using (reader = command.ExecuteReader())
{
dt = new DataTable();
dt.Load(reader);
ddl1.ValueMember = "col1";
ddl1.DisplayMember = "col2";
ddl1.DataSource = dt;
ddl2.ValueMember = "col1";
ddl2.DisplayMember = "col2";
ddl2.DataSource = dt;
ddl3.ValueMember = "col1";
ddl3.DisplayMember = "col2";
ddl3.DataSource = dt;
}
connection.Close();
}
}
}
However, when I execute this program, and make a selection from one of the comboboxes, the same value automatically gets selected from the other comboboxes. Any idea why this is happening and how to stop it from happening more importantly?
If I create 3 functions, 1 for each combobox, then everything works fine.
This project is a Word Document level project for Word 2010 created using .NET-4.0 using VS2013.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…