views:

15

answers:

0

Hi all,

Consider a serviceCall which returns an object:

// the int is the ID!
Dictionary<int, Dictionary<MyObject, List<AnotherObject>>> theData = Service.GetData();

MyObject looks like this:

class MyObject
{
    public string Name { get;set;} 
}

I have 2 comboboxes.

Combobox1 : I want to display the int from the dictionary. So I create a new BindingSource

BindingSource mainBindingSource = new BindingSource();
mainBindingSource.DataSource = theData; // the data we got from the service

theFirstComboBox.DataSource = mainBindingSource;
theFirstComboBox.DisplayMember = "Key"; // show the key from the dictionary

Plain & simple.

But, now I want a secondary Combobox and therein I want to be able to switch between the different MyObject in the dictionary.

Now this does not work, I can't get my second combobox to update with the following code (even though I change the selected ID in the first one):

BindingSource subBindingSource = new BindingSource();
subBindingSource.DataMember = "Value";  // the value from the DictionaryEntry<int, Dictionary<MyObject, List<AnotherObject>>>, so that is the Dictionary<MyObject, List<AnotherObject>>
subBindingSource.DataSource = mainBindingSource;

this.secondComboBox.DataSource = subBindingSource;
this.secondComboBox.DisplayMember = "Key.Name"; // I want to display the names of MyObject

When I change the value of the first combobox and I break the value of mainBindingSource.Current IS updated. So that is correct. It is reflected in the subBindingSource. But that update is not reflected in the second combobox. Why is that? :(

Thanks,

-Kristof