Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:57:08+00:00 2026-05-27T07:57:08+00:00

I have nested ObsevableCollections as seen below. For simplistic reason this is sample code

  • 0

I have nested ObsevableCollections as seen below. For simplistic reason this is sample code of what I am trying to accomplish.

Sample application the contains a ObservableCollection Team

    class MyApplication2
    {
        ObservableCollection<Team> _Teams = new ObservableCollection<Team>();
        public MyApplication2()
        {
            _Teams.Add(new Team("Team1"));
            _Teams.Add(new Team("Team2"));
            _Teams.Add(new Team("Team3"));

            foreach (Team t in _Teams)
            {
                t.Territories.Add(new Territory("Territory1"));
                t.Territories.Add(new Territory("Territory2"));
                t.Territories.Add(new Territory("Territory3"));
            }
        }
    }

Team object that contains an ObservableCollection Territory object

    class Team
    {
        private string _TeamName = "";
        private int _TeamProperty1 = 0;
        ObservableCollection<Territory> _Territories = new ObservableCollection<Territory>();

        public Team(string tName)
        {
            this.TeamName = tName;
        }

        public ObservableCollection<Territory> Territories
        {
            get { return _Territories; }
            set { _Territories = value; }
        }

        public string TeamName
        {
            get { return _TeamName; }
            set { _TeamName = value; }
        }

        public int TeamProperty1
        {
            get { return _TeamProperty1; }
            set { _TeamProperty1 = value; }
        }

    }

Territory object

    class Territory
    {
        private string _TerritoryName = "";

        public Territory(string tName)
        {
            this.TerritoryName = tName;
        }

        public string TerritoryName
        {
            get { return _TerritoryName; }
            set { _TerritoryName = value; }
        }

        public void Method1()
        {
            //Do Some Work
        }
    }

Just for this example I assigned t a value but in my real code I have the object t from some other means. t is an object type of territory in an ObservableCollection of Territories inside and object of a Team.

        public void SomeWork()
        {
            Territory t = _Teams[1].Territories[0];
            SomeMoreWork(t);
        }

I am removing a territory from 1 team and adding it to another team. Something like the following. How I get what Team object the territory belongs to?

        public void SomeMoreWork(Territory t)
        {
            Team _Team = ( Parent of t? );
            _Team.Territories.Remove(t);
            _Teams[0].Territories.Add(t);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:57:08+00:00Added an answer on May 27, 2026 at 7:57 am

    Thank you for the info Vincent Piel.

    Thank you for the idea Saad Imran.

    I changed the following and added an AssociatedTeam to my territory object and set it in the consructor. So far it seems to do what Im looking for.

        class Territory
        {
            private string _TerritoryName = "";
            Team _AssociatedTeam = null;
    
            public Territory(string tName, Team team)
            {
                this.TerritoryName = tName;
                this.AssociatedTeam = team;
            }
    
            public Team AssociatedTeam
            {
                get { return _AssociatedTeam; }
                set { _AssociatedTeam = value; }
            }
    
            public string TerritoryName
            {
                get { return _TerritoryName; }
                set { _TerritoryName = value; }
            }
    
    
            public void Method1()
            {
                //Do Some Work
            }
        }
    

    And then change the initiation of territory in the constructor of MyApplication

            t.Territories.Add(new Territory("Territory1", t));
            t.Territories.Add(new Territory("Territory2", t));
            t.Territories.Add(new Territory("Territory3", t));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have nested divs like this (pseudo code..) <div0> <div1></div1> <div2>fluid width</div2> <div3></div3> </div0>
I have nested xsl:for loops: <xsl:for-each select=/Root/A> <xsl:for-each select=/Root/B> <!-- Code --> </xsl:for> </xsl:for>
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
I have nested routes like this : map.resources :foo do |foo| foo.resources :bar do
I have nested repeaters like this: <asp:Repeater ID=rptQuestoes runat=server> <HeaderTemplate> <ol class=orderedList> </HeaderTemplate> <ItemTemplate>
I have nested resources like this in my routes.rb - ( my rake:routes gist
I have nested groupboxes, which logically represent nested data structures in my application. Let's
I have seen many posts about using ActivityGroups for when you have nested activities
I have a rails application that models a house. house contains rooms and rooms
I have nested li, which is for horizontal subnav menu. I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.