This is a migrated thread and some comments may be shown as answers.

nodes duplicating with serverside drag n drop and load on demand

7 Answers 107 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Toby
Top achievements
Rank 1
Toby asked on 18 Aug 2009, 08:24 AM
Hi,

I have a treeview loading dynamically from a web service which is all working fine. I have enabled server side drag n drop with a AjaxManager linked to the treeview.

It all works fine, but if you drag a node to a currently collapsed node, it will show the new node just dragged to it (as if it is expanded) but wont show the existing nodes until you manually click on it (where it loads from the webservice) Once it has done the load from the webservice it will then have a duplicate node of the one you have just added.

This issue sort of makes sences as in the drag n drop function it is adding the node from the serverside and then when the node is clicked it loads all the nodes from the database which will included the node that has just been moved - so will result in a duplicate.
private void PerformDragAndDrop(RadTreeViewDropPosition dropPosition, RadTreeNode sourceNode, 
         RadTreeNode destNode) 
        { 
            if (sourceNode.Equals(destNode) || sourceNode.IsAncestorOf(destNode))             
                return
             
            sourceNode.Owner.Nodes.Remove(sourceNode); 
             
            int iSourceNodeParentId = -1; 
            int iSourceNodeId = Convert.ToInt32(sourceNode.Value); 
            int iDestinationNodeId = Convert.ToInt32(destNode.Value); 
            if (sourceNode.ParentNode != null
                iSourceNodeParentId = Convert.ToInt32(sourceNode.ParentNode.Value); 
            else 
                iSourceNodeParentId = -1; 
 
            int iGroupViewId = Convert.ToInt32(sourceNode.Attributes["GROUPVIEWID"]); 
             
            WebSession webSess = (WebSession)Session["WebSession"]; 
 
            switch (dropPosition) 
            { 
                case RadTreeViewDropPosition.Over: 
                    // child 
                    if (!sourceNode.IsAncestorOf(destNode)) 
                    { 
                        destNode.Nodes.Add(sourceNode); 
                        // update db                         
                        webSess.MasterSystem.GroupsSystem.MoveNode(sourceNode.Value, destNode.Value); 
                    } 
                    break
 
                case RadTreeViewDropPosition.Above: 
                    // sibling - above                     
                    destNode.InsertBefore(sourceNode); 
                    // update db                         
                    webSess.MasterSystem.GroupsSystem.MoveNodeOrder(iSourceNodeId, iSourceNodeParentId, iGroupViewId, ConfigurationConsts.NodeOrderDirection.nodUp); 
                    break
 
                case RadTreeViewDropPosition.Below: 
                    // sibling - below 
                    destNode.InsertAfter(sourceNode); 
                    // update db                         
                    webSess.MasterSystem.GroupsSystem.MoveNodeOrder(iSourceNodeId, iSourceNodeParentId, iGroupViewId, ConfigurationConsts.NodeOrderDirection.nodDown); 
                    break
            }             
        } 

is there anyway rather than adding the node in this function - to just cause a reload from the webservice of the parent node where the node has just been dragged to - so instead of adding the node in manually - it can just load the information from the webservice.

Unless theres something else i should be doing?

thanks
Toby

7 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 20 Aug 2009, 01:32 PM
Hi Toby Moxha,

The problem seems to be fixed in the latest version - Q2 2009. Please download it and test it.

Kind regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Toby
Top achievements
Rank 1
answered on 20 Aug 2009, 01:39 PM
Hi,

Thanks for the reply, I am already using Q2 2009

thanks
Toby



0
Toby
Top achievements
Rank 1
answered on 20 Aug 2009, 01:49 PM
is this not due to the fact that in the drag n drop code we are adding a node :

destNode.Nodes.Add(sourceNode);  

and then the treeview reloads from the webservice which then results in a duplicate (as the new node is present in the dataset returned from the webservice).
0
Veselin Vasilev
Telerik team
answered on 21 Aug 2009, 08:51 AM
Hi Toby Moxha,

Yes, I suppose that is the problem. What you can do is to clear the child nodes in OnClientNodePopulating event.

All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Toby
Top achievements
Rank 1
answered on 21 Aug 2009, 09:04 AM
thanks that seems a bit better but I can still get them to duplicate sometimes (its seems to be when dragging from a child to a parent, where the parent has just had a node added to it.

would it not be better to not add the node from server side at all (using destNode.Nodes.Add(sourceNode); )  and instead just use the webservice to populate the treeview (as the website will be up to date with the node data as it has been updated in the database.

Edit:

I have just tried not adding the nodes from the server side - which works fine. But I can still get the treeview nodes to sometimes duplicate when dragging items around - if you do a full refresh it is fine. is there a way to force all the nodes to rebind to the website (but keep the current heirachy open)
0
Veselin Vasilev
Telerik team
answered on 26 Aug 2009, 12:19 PM
Hello Toby Moxha,

I am not sure why it behaves that way and I think it would be better if you open a support ticket and send us a sample project which demonstrates the problem.


Sincerely yours,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Toby
Top achievements
Rank 1
answered on 17 Sep 2009, 11:50 AM
for anyone else with this issue the solution was :


A few quick tweaks fixed the first problem easily. In the PerformDragAndDrop server method you should add the dropped node to the destination node only if the destination node is expanded:



   if (destNode.Expanded || destNode.Nodes.Count == 0)
   {
            destNode.Nodes.Add(sourceNode);
   }


Tags
TreeView
Asked by
Toby
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Toby
Top achievements
Rank 1
Share this question
or