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

SharePoint: TreeView control with drag and drop

1 Answer 125 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
jasear
Top achievements
Rank 1
jasear asked on 18 Jun 2009, 01:15 PM
Hi,

I am trying to implement a treeview control with drag and drop however the drag and drop bit doesnt seem to be working.

I have looked at the draganddrop example but it is handling drag and drop between two TreeView controls.

I am just using 1 and I was hoping to find an example where I can see it implementing drag and drop. I have set the EnableDragAndDropBetweenNodes and EnableDragAndDrop properties but when I drag something to another node it simply refreshes the page and does nothing. Do I need to subscribe to one of the events and do something in there to ensure the draganddrop happens?
Thanks

1 Answer, 1 is accepted

Sort by
0
jasear
Top achievements
Rank 1
answered on 18 Jun 2009, 01:30 PM
Ok thanks I got this working. For the reference of others encountering the same problem. You need to subscribe to the NodeDrop event and do the following:

        protected void RtvTags_NodeDrop(object sender, RadTreeNodeDragDropEventArgs e)  
        {  
            PerformDragDrop(e);  
        }  
        /// <summary>  
        /// Performs the drag drop.  
        /// </summary>  
        /// <param name="e">The <see cref="Telerik.Web.UI.RadTreeNodeDragDropEventArgs"/> instance containing the event data.</param>  
        private void PerformDragDrop(RadTreeNodeDragDropEventArgs e)  
        {  
            RadTreeNode sourceNode = e.SourceDragNode;  
            RadTreeNode destinationNode = e.DestDragNode;  
 
            if (destinationNode != null)  
            {  
                MoveNode(e.DropPosition, sourceNode, destinationNode);  
            }            
        }  
        /// <summary>  
        /// Moves the node.  
        /// </summary>  
        /// <param name="dropPosition">The drop position.</param>  
        /// <param name="sourceNode">The source node.</param>  
        /// <param name="destNode">The dest node.</param>  
        private void MoveNode(RadTreeViewDropPosition dropPosition, RadTreeNode sourceNode, RadTreeNode destNode)  
        {  
            if (sourceNode == destNode || sourceNode.IsAncestorOf(destNode))  
            {  
                return;  
            }  
            sourceNode.Owner.Nodes.Remove(sourceNode);  
            switch (dropPosition)  
            {  
                case RadTreeViewDropPosition.Over:  
                    // child  
                    if (!sourceNode.IsAncestorOf(destNode))  
                    {  
                        destNode.Nodes.Add(sourceNode);  
                        destNode.Expanded = true;  
                    }  
                    break;  
                case RadTreeViewDropPosition.Above:  
                    // sibling - above                    
                    destNode.InsertBefore(sourceNode);  
                    break;  
                case RadTreeViewDropPosition.Below:  
                    // sibling - below  
                    destNode.InsertAfter(sourceNode);  
                    break;  
            }  
            sourceNode.Selected = false;  
        } 
Tags
TreeView
Asked by
jasear
Top achievements
Rank 1
Answers by
jasear
Top achievements
Rank 1
Share this question
or