473,387 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Copy nodes of one treeview to another

Hi
How to copy treeview.Nodes from one treeview to another.
Is this posible to do this in one line ? ( Calling some function )
Sep 21 '06 #1
3 22809
I have found the answer ( if someone will need in the future ):

TreeNodeCollection myTreeNodeCollection = myTreeViewBase.Nodes;
// Create an array of 'TreeNodes'.
TreeNode[] myTreeNodeArray = new TreeNode[myTreeViewBase.Nodes.Count];
// Copy the tree nodes to the 'myTreeNodeArray' array.
myTreeViewBase.Nodes.CopyTo(myTreeNodeArray,0);
// Remove all the tree nodes from the 'myTreeViewBase' TreeView.
myTreeViewBase.Nodes.Clear();
// Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
myTreeViewCustom.Nodes.AddRange(myTreeNodeArray);
Sep 21 '06 #2
A function like this should do it.

void CopyNodes(TreeView from, TreeView to)
{
foreach (TreeNode node in from)
{
to.Nodes.Add(node.Clone());
}
}

HTH

Ciaran O'Donnell
"PiotrKolodziej" wrote:
Hi
How to copy treeview.Nodes from one treeview to another.
Is this posible to do this in one line ? ( Calling some function )
Sep 21 '06 #3
That moves them, rather than copies them like you originally requested. If
that is what you want to do then use this as CopyTo uses Array.Copy which is
faster then just a loop.

Ciaran O'Donnell
"PiotrKolodziej" wrote:
I have found the answer ( if someone will need in the future ):

TreeNodeCollection myTreeNodeCollection = myTreeViewBase.Nodes;
// Create an array of 'TreeNodes'.
TreeNode[] myTreeNodeArray = new TreeNode[myTreeViewBase.Nodes.Count];
// Copy the tree nodes to the 'myTreeNodeArray' array.
myTreeViewBase.Nodes.CopyTo(myTreeNodeArray,0);
// Remove all the tree nodes from the 'myTreeViewBase' TreeView.
myTreeViewBase.Nodes.Clear();
// Add the 'myTreeNodeArray' to the 'myTreeViewCustom' TreeView.
myTreeViewCustom.Nodes.AddRange(myTreeNodeArray);
Sep 21 '06 #4

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

Similar topics

5
by: Chris | last post by:
Hi, Maybe I've got a strange question. I've got a XML document (main.xml) with several nodes. Additional I've another XML docuement (role.xml), with allowed nodes. In a XSL-File I just would...
5
by: Daniel Tan | last post by:
Are there anyway to copy rows of records from one query to another query and then hide the records in source query ? Pls advise. Thanks. Regards, Daniel
1
by: Trint Smith | last post by:
In vs.net I have a webform with controls I neet to copy to another page...when I cut and paste them, the are on top of the destination pages controls and I can't re-select them to drag them to the...
4
by: Marc R. | last post by:
Hi all, I won't ask an complete example here but some good links for that issue would be perfect. (the I will only need to do the save function to save the current position of the nodes) ...
1
by: Pauljh | last post by:
Hi All, I have a web page which builds a hidden table, as (based on certain criteria) people can have multiple version of this table, not a problem. But I need each table to have a unique id...
2
by: nosipho | last post by:
Hello guys, I need to copy a database in SQL 2000 to another SQL2000 server. I tried backing up the database to a folder then restore it but it's not happening. Please help to know how to copy...
1
by: Praveen | last post by:
Two XML's XmlDocument TempDom = new XmlDocument(); TempDom.loadXML("<R Flg='1'><I N='Zero'/></R>"); XmlDocument ResultDom = new XmlDocument(); ResultDom.loadXML("<R><I N='One'/><I N='Two'/><I...
0
by: Phill W. | last post by:
I'm trying to implement Drag-and-Drop within a TreeView. Back in VB "Proper", I'd have use the Treeview's DropHighlight property to give the user an indication of where they're about to drop...
0
by: ferlarroca | last post by:
Hi, I am trying to copy a range below another one...... I have defined two ranges as follow: Dim r1 As Range Dim r2 As Range Set r1 = Sheets("Old Index").Range("A9:A200, H9:H200, K9:K200")...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.