Articles in this section
Category / Section

How to restrict drag and drop for particular nodes in Syncfusion Blazor TreeView component?

2 mins read

The drag and drop action in Blazor TreeView component can be prevented to particular node by using OnNodeDragStop event by setting args.Cancel property as true.

@using Syncfusion.Blazor.Navigations

<SfTreeView TValue="TreeData" AllowDragAndDrop="true">
    <TreeViewEvents TValue="TreeData" OnNodeDragStop="OnNodeDragStop"></TreeViewEvents>
    <TreeViewFieldsSettings DataSource="@TreeDataSource" Id="Id" ParentID="Pid" Text="Name" HasChildren="HasChild"              Expanded="Expanded"></TreeViewFieldsSettings>
</SfTreeView>
       
@code{
   List<TreeData> TreeDataSource = new List<TreeData>();
   
   public void OnNodeDragStop(DragAndDropEventArgs args)
   {
       if (args.DraggedNodeData.Id == "1")
       {
           args.Cancel = true;
       }
   }

   protected override void OnInitialized()
   {
       base.OnInitialized();
       GetTreeData();
   }

   private void GetTreeData(){
       TreeDataSource.Add(new TreeData
       {
           Id = "1",
           Name = "Discover Music",
           HasChild = true,
           Expanded = true
       });
       TreeDataSource.Add(new TreeData
       {
           Id = "2",
           Pid = "1",
           Name = "Hot Singles",
       });
       ...
       ...
    }
  }

Sample: https://blazorplayground.syncfusion.com/BNhfZAZlpPJuzWrr

Conclusion
I hope you enjoyed learning about how to restrict drag and drop for particular nodes in Syncfusion Blazor TreeView component.

You can refer to our Blazor TreeView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor TreeView example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied