1

I have a simple WinForm, a CR report and a class that allow the user to pass parameters to the Crystal Report.

The user is presented with 2 options to control what is shown in the report.

WinForm:
Customer ID: [dropdownlist1] to [dropdownlist2]
Customer Name: [dropdownlist3] to [dropdownlist4]
[OK][Cancel]

Basically, the above WinForm allows the user to select a range of customer id and/or name from A to Z.

I connect to the database and using List.Add(new Customer(id, name)) to get all the fixated 200 records (the Customer DB table is fixed and will not grow according to our user) returned from the Customer DB table.

In my code,

var customer1 = new Customer();

//Do DB connection and loop through the record and add to List<T>
//List<Customer>.Add(new Customer(reader.GetInt16(0), reader.GetString(1)));

dropdownlist1.ValueMember = "customerID";
dropdownlist1.DisplayMember = "customerID";
dropdownlist1.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

dropdownlist2.ValueMember = "customerID";
dropdownlist2.DisplayMember = "customerID";
dropdownlist2.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

dropdownlist3.ValueMember = "customerName";
dropdownlist3.DisplayMember = "customerName";
dropdownlist3.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

dropdownlist4.ValueMember = "customerName";
dropdownlist4.DisplayMember = "customerName";
dropdownlist4.DataSource = customer1.GetCustomerList(); //Return List<Customer>()

The problem I faced is, after the WinForm is loaded, and whenever I were to make a selection change in dropdownlist1, all the remaining 3 dropdownlists will change to the one I have selected in dropdownlist1. This is the same situation for other list selection I made.

What happened? How can I make individual list behave on its own unless I made the change in each of the dropdown list?

StuartLC
  • 104,537
  • 17
  • 209
  • 285
furor
  • 43
  • 9
  • This looks [like a duplicate](http://stackoverflow.com/a/10239016/314291) - use a `new BindingContext()` in between `DataSource` assignments – StuartLC Nov 25 '14 at 17:04
  • @StuartLC Oh so awesome. For somethings like this, I don't even know what to ask or google for. Usually I would have done the usual google or forum search before I ask any question. – furor Nov 25 '14 at 18:00
  • @StuartLC Gosh! It worked! Thank you pal. (Oh man, it took me 15 minutes to draft that question out and it probably take you less than a minute to figure out what to search for) – furor Nov 25 '14 at 18:04
  • We've all come across this issue at some time or other :) - the `BindingSource` tracks the datasources by reference, so either need to create new collections (even if it has the same elements), or change the `BindingSource` – StuartLC Nov 25 '14 at 18:50
  • possible duplicate of [Multiple Combo Boxes With The Same Data Source (C#)](http://stackoverflow.com/questions/4344366/multiple-combo-boxes-with-the-same-data-source-c) – StuartLC Nov 25 '14 at 18:51

0 Answers0