All Products
Demos
Services
Blogs
Docs & Support
Pricing
Search
Shopping cart
Login
Contact Us
Get A Free Trial
close mobile menu
Telerik Forums
/
UI for ASP.NET AJAX Forum
/
TreeView
/
SharePoint: TreeView control with drag and drop
Cancel
Telerik UI for ASP.NET AJAX
Resources
Buy
Try
Feed for this thread
2 posts, 0 answers
jasear
29 posts
Member since:
Jan 2007
Posted 18 Jun 2009
Link to this post
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
jasear
29 posts
Member since:
Jan 2007
Posted 18 Jun 2009
Link to this post
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
;
}
Back to Top
Close