Iterating through items of CompositeCollection

Posted by Dudu on Stack Overflow See other posts from Stack Overflow or by Dudu
Published on 2010-06-09T09:56:15Z Indexed on 2010/06/09 10:02 UTC
Read the original article Hit count: 191

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about .NET

Related posts about compositecollection