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

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Switch Node Positions
Link Posted: 02-Nov-2006 03:20
I am working with ASP.NET 1.1.  For following tree:

TreeView or Parent Node
-- Node 1
-- Node 2 -> is selected
-- Node 3
-- Node 4

Can I changed the node position of Node 2 with Node 3 using Javascript, clientside?  How can I do this?

Thank you.
Link Posted: 02-Nov-2006 04:10
It is a complex task for FlyTreeView for ASP.NET 1.1 because it lacks some node management client-side functions.

Client-side TreeNode object (as you can see from node.htc headers) contains
AddNode(node) and Remove() methods.

You cannot specify the index of a desired place to insert the node.

So the only way is to remove all the next sibling nodes and insert them in a proper way. But this seems to have performance issues.
Link Posted: 09-Nov-2006 00:24
just what I wanted to ask!, but then version 2.0....

how can I do this using 2.0?
Link Posted: 09-Nov-2006 01:19
CFlyTreeNode.insertNode(nodeToInsert, index);
is available in FlyTreeView for ASP.NET 2.0 though still not documented.

So just remove first and second node using remove() method and insert them into required positions.
Link Posted: 09-Nov-2006 01:45
I acutally meant that I wanted to do this in de dropnode handler

function ftvMenu_OnDrop(targetnode, event)

The user drops a node on some other node. The droped node should then be inserted UNDER the node it was dropped in (not IN, not as a child)

Like this:

Node1
--child1
--child2  --< release child5 here
--child3
--child4

result:

Node1
--child1
--child2
--child5
--child3
--child4

So, the way i vision it, in ftvMenu_OnDrop eventhandler, I replace the targetnode for targetnode.parent, and set the index to the index+1 of the original target. Like this

function ftvMenu_OnDrop(targetnode, event)
{
  var index=parent.index;
  targetnode=targetnode.parent;
  flytreeview_dragObject.index=index;
}

and this should be implemented at 1600 hours this day (it is now 13:44) ))

edit:

I tried this:

var i=target.i;                        
var parentnode=target.getParent();
parentnode.insertNode(flytreeview_dragObject.value, i+1);

but keep getting an exception: \"invalid acces to function to be used with node without owner treeview\"
Link Posted: 09-Nov-2006 02:21
[code] <%@ Register Assembly=\"NineRays.WebControls.FlyTreeView\" Namespace=\"NineRays.WebControls\" TagPrefix=\"NineRays\" %> Untitled Page
function ftvMenu_OnDrop(target, event) { var parentNode = target.getParent(); var index = target.i; var node = flytreeview_dragObject.value; node.remove(); // remove first from previous location parentNode.insertNode(node, index); return false;// to skip default action } [/code]
Link Posted: 09-Nov-2006 03:19
You are the best! thanx for helping me save my ass ;-)

One small issue in your code was that if you would drop to a node in the root, you would get an exception and also if you would drop to de rootdropzone.

Final code:

var parentNode;
                          var parentNode;
  var targetIndex;
  if (target instanceof CFlyTreeView)
  {
    // target=rootdropzone
    parentNode=target;
    targetIndex=target.getNodes().length;
  }
  else
  {
    var parentNode = target.getParent();
    if (parentNode == null) parentNode=target.getTreeview(); //target=rootobject
    targetIndex=target.i;
  }
  
  var node = flytreeview_dragObject.value;
  node.remove(); // remove first from previous location
  parentNode.insertNode(node, targetIndex);
  
  return false;// to skip default action