0

I am building an application which connects to a database through the Microsoft entity model framework built in Visual Studio 2010.

This is my problem:

I have two ComboBox which are using the table Places. Every time I change the selected item of one of these ComboBoxes, the other box changes it too. This means I have always the same value on both combo boxes.

The two ComboBoxes.

I think this has to do with the entity they are sharing. How can I split it up? I'd prefer not to make two database tables, and to keep it stupid simple.

Here is how I bind the two comboboxes to the entity.

this.comboBoxDeparturePlace.DataSource = this.m_DatabaseEntity.Places;
this.comboBoxDestinationPlace.DataSource = this.m_DatabaseEntity.Places;

Thanks for your help!

EDIT:

My Model looks like this:

Model

The SelectedItem is a place with those properties (ID, DisplayName, PostalCode, Name)

The DisplayName is the value being displayed on the ComboBox.

The ID is the SelectedValue.

El Mac
  • 3,256
  • 7
  • 38
  • 58

1 Answers1

0

I solved this problem / behaviour.

I guess the entity table uses an index, similar to a databinding source. Every time the SelectedItem changed, it changed the index on the table, and that changed the SelectedItem of the other ComboBox.

I created two lists, before I used them as a DataSource. The two lists will have an own index and will therefore be separated completely from eachother.

List<Place> placeListFrom = new List<Place>(this.m_DatabaseEntity.Places);
List<Place> placeListTo = new List<Place>(this.m_DatabaseEntity.Places);

this.comboBoxDeparturePlace.DataSource = placeListFrom;
this.comboBoxDestinationPlace.DataSource = placeListTo;
El Mac
  • 3,256
  • 7
  • 38
  • 58