c# - Comboboxes are linked for some reason -


i have following code 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 execute program, , make selection 1 of comboboxes, same value automatically gets selected other comboboxes. idea why happening , how stop happening more importantly?

if create 3 functions, 1 each combobox, works fine.

this project word document level project word 2010 created using .net-4.0 using vs2013.

new improved solution:

looks there hidden default bindingsource makes comboboxes follow.

to avoid coupling , data replication in first version of answer, need create separate bindingsource each combobox. these share datatable have each own rowpointer:

bindingsource bs1, bs2, bs3; .. ..     .. ..     dt = new datatable(); dt.load(reader);  bs1 = new bindingsource(); bs1.datasource = dt;  bs2 = new bindingsource(); bs2.datasource = dt;  bs3 = new bindingsource(); bs3.datasource = dt; .. ddl1.datasource = bs1 ; ddl2.datasource = bs2 ; ddl3.datasource = bs3 ; .. .. 

now comboboxes can changed independently.

note: first version worked wrong way it. sorry..!


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -