New to Telerik UI for Blazor? Download Free 30-day trial
TreeView - Drag & Drop
- EXAMPLE
- VIEW SOURCE
- EDIT IN TELERIK REPL
- Change Theme
default
- Drag-drop.razor
Description
Telerik UI for Blazor TreeView displays data in a tree-like structure. One of the main functionalities it gives is drag and drop. It allows you to move a node or multiple nodes between different parents in the same Treeview or between different component instances.
To enable the drag and drop functionality, set the Draggable
parameter to true
. Then, use the OnDrop
event to handle the drag and drop operations and modify the data source as per the application business logic.
The OnDrop
event fires when dropping a node into a new location. That allows you to manipulate the data collection based on where the user dropped the element.
You can find the following fields in the OnDrop
arguments of type TreeViewDropEventArgs
:
Item
- an object that represents the dragged node. It can get cast to your model class.DestinationItem
- an object that represents the node over which the Item is dropped to. It can get cast to your model class.DropPosition
- anenum
- its members allow you to determine the exact position of the dropped item relative to the position of theDestinationItem
:After
Below
Over
DestinationTreeView
- the reference of the TreeView in which the node is dropped. That is applicable when you drag and drop nodes between different instances of the component.
Note that - the OnDrop
event fires for the TreeView where the item originally was if you drag and drop items from one instance of the TreeView to another.