Adding the same TreeNode to two nodes in a TreeView

Discussion in 'ASP General' started by Turban, Apr 21, 2006.

  1. Turban

    Turban Guest

    When I attempt to run the following code:

    protected void NavigationTreeView_TreeNodePopulate(object sender,
    TreeNodeEventArgs e) {
    TreeNode tn1 = new TreeNode("node1","node1");
    TreeNode tn2 = new TreeNode("node2", "node2");
    TreeNode newNode = new TreeNode("add me to both nodes", "add me to
    both nodes");
    e.Node.ChildNodes.Add(tn1);
    e.Node.ChildNodes.Add(tn2);
    tn1.ChildNodes.Add(newNode);
    tn2.ChildNodes.Add(newNode);
    }

    It does not behave as expected. Instead of adding a copy of newNode to each
    of the other two nodes, it adds to tn1 and then when it adds it to tn2 it
    removes it from tn1, thus in the end only tn2 has the newNode and tn1 has no
    children. This surprises me. How can I add the same node to two separate
    locations in a treeview?
    Turban, Apr 21, 2006
    #1
    1. Advertising

  2. Turban

    Mike Brind Guest

    Turban wrote:
    > When I attempt to run the following code:
    >
    > protected void NavigationTreeView_TreeNodePopulate(object sender,
    > TreeNodeEventArgs e) {
    > TreeNode tn1 = new TreeNode("node1","node1");
    > TreeNode tn2 = new TreeNode("node2", "node2");
    > TreeNode newNode = new TreeNode("add me to both nodes", "add me to
    > both nodes");
    > e.Node.ChildNodes.Add(tn1);
    > e.Node.ChildNodes.Add(tn2);
    > tn1.ChildNodes.Add(newNode);
    > tn2.ChildNodes.Add(newNode);
    > }
    >
    > It does not behave as expected. Instead of adding a copy of newNode to each
    > of the other two nodes, it adds to tn1 and then when it adds it to tn2 it
    > removes it from tn1, thus in the end only tn2 has the newNode and tn1 has no
    > children. This surprises me. How can I add the same node to two separate
    > locations in a treeview?


    If you had read a few posts within this group before making yours -
    just to make sure that you were posting to a relevant group and not
    wasting your time - you would very quickly have come across something
    like this:

    This group covers classic ASP. Dotnet is a different technology. Try
    posting your question to microsoft.public.dotnet.framework.aspnet.

    or

    There was no way for you to know it (except maybe by browsing through
    some
    of the previous questions before posting yours - always a recommended
    practice), but this is a classic asp newsgroup.
    ASP.Net is a different technology from classic ASP.
    While you may be lucky enough to find a dotnet-savvy person here who
    can
    answer your question, you can eliminate the luck factor by posting your
    question to a newsgroup where the dotnet-savvy people hang out. I
    suggest
    microsoft.public.dotnet.framework.aspnet.

    or

    This group is for classic ASP. Direct questions regarding ASP.NET to
    microsoft.public.dotnet.framework.aspnet[.*] newsgroups.

    --
    Mike Brind
    Mike Brind, Apr 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gavnosis
    Replies:
    0
    Views:
    498
    gavnosis
    Aug 2, 2003
  2. tanya foster
    Replies:
    3
    Views:
    3,691
    tanya foster
    May 18, 2006
  3. mazdotnet
    Replies:
    0
    Views:
    757
    mazdotnet
    Aug 1, 2006
  4. abargaddon
    Replies:
    0
    Views:
    1,035
    abargaddon
    Jan 17, 2008
  5. Per Salmi

    TreeView not rendering nodes? Cacheing of a TreeView

    Per Salmi, Oct 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    440
    Steve Drake
    Oct 15, 2003
Loading...

Share This Page