473,662 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding the same TreeNode to two nodes in a TreeView

When I attempt to run the following code:

protected void NavigationTreeV iew_TreeNodePop ulate(object sender,
TreeNodeEventAr gs 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.ChildNod es.Add(tn1);
e.Node.ChildNod es.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?
Apr 21 '06 #1
1 2878

Turban wrote:
When I attempt to run the following code:

protected void NavigationTreeV iew_TreeNodePop ulate(object sender,
TreeNodeEventAr gs 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.ChildNod es.Add(tn1);
e.Node.ChildNod es.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.publi c.dotnet.framew ork.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.publi c.dotnet.framew ork.aspnet.

or

This group is for classic ASP. Direct questions regarding ASP.NET to
microsoft.publi c.dotnet.framew ork.aspnet[.*] newsgroups.

--
Mike Brind

Apr 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1348
by: serge calderara | last post by:
Dear all, I have an application which timely create log file in XML format I ma using the SystemFileWatcher object to monitor creation of new file in the proper path. So far no problem When the first file is created, my SystemFile onchanged event is catch and then I add the new log file in a treview control with the following code: Dim m_Root As New TreeNode
4
5257
by: Jeroen Ceuppens | last post by:
Hi, I want to make something that adds a TreeNode to the end of TreeView, that TreeView Looks like + Level 1 + Level 2 + Level 3 - Level last
9
5482
by: James Geurts | last post by:
Hey all... I posted this in the vs.net ide group too, but people are not answering, so I figured that it might be more appropriate here. I'm not sure if I'm adding a designer to my code properly. I'm only adding it to the tree node, where each custom tree node is then added to a normal tree control I'm trying to get an add-in to interact with the property window in VS.Net. Basically, I created a tool window containing a custom tree...
10
2011
by: Dan Nash | last post by:
Hi peeps.. Im using the TreeView control from IE COntrols to create a directory structure, and trying to do it recursively. The code works, but my question is simply how can I make the subdirs appear as leaves in the Tree, rather than as new branches? Here's the code..
3
1831
by: markaelkins | last post by:
Hi. I am trying to enter a variable in the treenodesrc of a treenode. I am basically trying to send an ID variable into sql to return different records. I've searched everywhere and cannot find the answer. I'd appreciate and help. Thanks. What I'm doing is creating a treeview with the structure as follows (this is the expanded view): - Item Status - Item Status Details
4
3591
by: Turban | last post by:
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);
3
2253
by: Ray Booysen | last post by:
Hi all I have a treeview bound to a sitemap. Once the user is logged in, I'm wanting the menu to expand to include additional items from a database while retaining the items in the sitemap. Is this possible. For example. My menu has an item called "Books" defined in the sitemap. Once the user logs in, I want sub menu-items to be created under books with all
6
2506
by: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node ?? When adding a new node is there any way to get an handle or something else to be able add the childs to the correct parent ? Thanks!
1
1902
by: Bart Steur | last post by:
Hi As a VB6 user I'm unfamiliar with the Treeview control of VB2005. I read it was changed but I have a hard time finding the right help/samples for my problem. In VB6 you had 1 collection, and adding a node was quite simple. Just specify the nodes key and position relative to the key where you want to add your new node. In VB2005 you can't do that anymore. I looking for a sample or help how this
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8344
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.