Home - Forums-.NET - FlyTreeView (ASP.NET) - Switching Node Positions

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Switching Node Positions
Link Posted: 27-Oct-2006 09:12
A node has many child nodes:

I am trying to switch the position of 2 adjacent nodes using following:

NineRays.Web.UI.WebControls.FlyTreeView.TreeNode node1 = new NineRays.Web.UI.WebControls.FlyTreeView.TreeNode();
NineRays.Web.UI.WebControls.FlyTreeView.TreeNode node2 = new NineRays.Web.UI.WebControls.FlyTreeView.TreeNode();
        
node1 = (NineRays.Web.UI.WebControls.FlyTreeView.TreeNode) parent.Nodes[selectedNodeIndex-1].Clone();
node2 = (NineRays.Web.UI.WebControls.FlyTreeView.TreeNode) parent.Nodes[selectedNodeIndex].Clone();

parent.Nodes[selectedNodeIndex-1].Remove();
parent.Nodes[selectedNodeIndex].Remove();

parent.Nodes.AddAt(selectedNodeIndex-1,node2);
parent.Nodes.AddAt(selectedNodeIndex,node1);


it says \"TreeNode with the same Key is already in this collection\".  how could this be, i am removing the nodes before adding them back...
Link Posted: 27-Oct-2006 09:20
Try to interchange two lines
parent.Nodes[selectedNodeIndex-1].Remove();
parent.Nodes[selectedNodeIndex].Remove();


to

parent.Nodes[selectedNodeIndex].Remove();
parent.Nodes[selectedNodeIndex-1].Remove();
Link Posted: 27-Oct-2006 09:34
thank you for the quick reply.

relating to this, and i have issue with setting ParentNode:

NineRays.Web.UI.WebControls.FlyTreeView.TreeNode parent = (NineRays.Web.UI.WebControls.FlyTreeView.TreeNode) FTV.SelectedNode.Parent;


Compiles fine, but there is an issue at run time, \"Specified cast is not valid.\"

i saw some of your javascripts.  there seems to be \"ParentNode\" property.  is there something like that on code behind, c#?

or, what is the best way to set a parent node for a selected node?
Link Posted: 27-Oct-2006 09:39
got it solved.

actually, my code works when the swtich is made on 2nd level and below.

when the switch is tried on 1st expanded level, parent is treeview, which is a node...  silly me.

thank you.
Link Posted: 27-Oct-2006 10:59
Actually Parent may be a TreeNode or FlyTreeView object.

Parent implements INodesContainer interface, that has the only property - Nodes.

So you'd better cast to INodesContainer intead of TreeNode. This should solve the problem.
Link Posted: 03-Nov-2006 00:51
I must be missing something?

I have been completely rebuilding a tree level server side to switch the position of nodes, which works well other than an issue of hover / selected colour becoming a little muddled. I can't find reference to the AddAt method anywhere... Where should I be looking?

If this method exists client side then that would be fabulous (asp 2.0 here), as I do not need to know about individual node switches server side.

Many thanks.
Link Posted: 03-Nov-2006 08:22
There's insertNode(child, index) method. It is not documented though for some technical reasons. We will probably publish it within the next release.