6 Answers, 1 is accepted
RadTreeView handles the whole drag and drop operation by its TreeViewDragDropService. The PreviewDragOver event allows you to control on what targets the node element being dragged can be dropped on. If the target node is not allowed, set the CanDrop argument to false.
Please refer to the following help articles which will get you familiar with the TreeViewDragDropService and how you can control the drag and drop operation if some custom requirements occur:
https://docs.telerik.com/devtools/winforms/controls/treeview/drag-and-drop/treeviewdragdropservice
https://docs.telerik.com/devtools/winforms/controls/treeview/drag-and-drop/drag-and-drop-in-bound-mode
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
I didn't quite understand how to use it. I have already read this documentation.And only found the DragEnding event there. But TargetNode does not always indicate the parent Node where the dragged node is moved, and sometimes just the adjacent one when changing the order.
I made a special class with isDir property (He says whether it is possible to move the nodes inside). But I don't understand how to use it in DragEnding :(
public
class
RadTreeNode2 : RadTreeNode
{
public
bool
isDir =
false
;
public
RadTreeNode2()
{
}
public
RadTreeNode2(
string
text) :
base
(text)
{
}
}
protected
override
void
OnPreviewDragOver(RadDragOverEventArgs e)
{
base
.OnPreviewDragOver(e);
e.CanDrop = (e.HitTarget
as
RadTreeNode2).isDir;
}
This code not work :(
I also found this kind of documentation, but for some reason it does not work.Why it happens?
Using AllowDrop property
You can interrupt a drag and drop operation by setting the AllowDrop property of a specific RadTreeNode to false. This way you still can drag this particular node, but you cannot add other nodes to it with drag and drop operation. You can set this for any particular node you want.
Overriding the OnPreviewDragOver method of the custom TreeViewDragDropService or just subscribing to the TreeViewDragDropService.PreviewDragOver event is the appropriate solution to disable dragging over certain nodes. In the event arguments you have access to the target visual node element from where you can access the data node and determine whether the drop operation is allowed by its "isDir" value.
Specifying the AllowDrop property for the desired RadTreeNodes is also a suitable approach: https://docs.telerik.com/devtools/winforms/controls/treeview/drag-and-drop/cancel-a-drag-and-drop-operation
Feel free to use this approach which suits your requirements best. In case you are experiencing any further difficulties with the drag and drop functionality, it would be greatly appreciated if you can provide a sample project demonstrating the problem you are facing. Thus, we would be able to investigate the precise case and provide further assistance.
Should you have further questions please let me know.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.