Welcome Guest Search | Active Topics | Sign In | Register

Copy selected node from one treeview to another treeview Options
newnet
Posted: Tuesday, September 25, 2007 8:46:33 AM
Rank: Newbie
Groups: Member

Joined: 9/25/2007
Posts: 2
We are evaluating EO control and try to use treeview control to copy selected nodes from one treeview to another treeview. this action is triggered by one button click.

I can retrive both parent and child node from tree1, but don't know how to add to tree2 and still have this parent child relationship. does your tree control has something like copynode or clonenode so we can use? So far I used Treeview2.TopGroup.nodes.add(parentNode.Text)
and Tree2view.nodes.add(nd).

Thank you in advance!
eo_support
Posted: Tuesday, September 25, 2007 9:09:01 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

TreeView2.TopGroup.Nodes.Add(parentNode.Text) is the right way to go. There no direct way to copy one node from one TreeView to another TreeView. You basically add new nodes in the second TreeView based on whatever information you get from the first TreeView, just like you add nodes based on any other information.

In order to keep the parent child relationship, you will need to add both the parent node and the child nodes. It's very easy to do so:

Code: C#
EO.Web.TreeNode node = 
    TreeView2.TopGroup.Nodes.Add(parentNode.Text);
for (int i = 0; i < parentNode.ChilNodes.Count; i++)
    node.ChildNodes.Add(parentNode.ChildNodes[i].Text);


That should get you going.

Thanks
newnet
Posted: Tuesday, September 25, 2007 11:24:54 AM
Rank: Newbie
Groups: Member

Joined: 9/25/2007
Posts: 2
Thank you for your quick response. Yes, it is working. Thank you!!Angel

I have another question about the node delete function. iny my code, I want to delete the node which is checked but find all nodes are gone. Code is here:

foreach(EO.Web.TreeNode nd in node.SubGroup.Nodes)
{
if (nd.Checked)
node.SubGroup.Nodes.Remove(nd);
}

eo_support
Posted: Tuesday, September 25, 2007 8:45:15 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

You can't really delete items while you are looping through the collection. It's like moving the ladder that you are walking on. You can try to only delete one item and see what happens. Also you want to check the code that add the nodes. Sometimes it's not because the are all deleted, but because they were not correctly added at all.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.