Iterating through items of CompositeCollection
- by Dudu
Consider the code:
ObservableCollection<string> cities = new ObservableCollection<string>();
ObservableCollection<string> states = new ObservableCollection<string>();
ListBox list;
cities.Add("Frederick");
cities.Add("Germantown");
cities.Add("Arlington");
cities.Add("Burbank");
cities.Add("Newton");
cities.Add("Watertown");
cities.Add("Pasadena");
states.Add("Maryland");
states.Add("Virginia");
states.Add("California");
states.Add("Nevada");
states.Add("Ohio");
CompositeCollection cmpc = new CompositeCollection();
CollectionContainer cc1 = new CollectionContainer();
cc1.Collection = cities;
CollectionContainer cc2 = new CollectionContainer();
cc2.Collection = states;
cmpc.Add(cc1);
cmpc.Add(cc2);
list.ItemsSource = cmpc;
foreach(var itm in cmpc )
{
// itm is CollectionContainer and there are only two itm’s
// I need the strings
}
While list shows the right data on the GUI
I need this data (without referring to the ListBox) and I am not getting it