We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to restrict drag drop of parent node into another parent node but allow reordering parent nodes programmatically

To restrict the drag drop of parent node into another parent get the dragged treeview item and TargetDropItem using DragStart and DragEnd events respectively. In DragEnd event compare the ParentItemsControl of dragged item and TargetDropItem. If both the node are equal cancel the event.

XAML

 

C#

 

The following screenshot illustrates the output of the above code example

 

Article ID: Published Date: Last Revised Date: Platform: Control:
5793 11/27/2015 11/27/2015 WPF TreeViewAdv
Did you find this information helpful?
Comments
Krishna Kumar Nanjundaprasad Apr 04, 2017

I would actually write the treeview_DragEnd event handler as follows;

         private void SfTreeViewAdv_DragEnd(object sender, DragTreeViewItemAdvEventArgs e)
        {
            TreeViewItemAdv targetDropItem = e.TargetDropItem as TreeViewItemAdv;
            if (_draggedItem == null)
            {
                e.Cancel = true;
                return;
            }
            if (targetDropItem == null)
            {
                e.Cancel = true;
                return;
            }
            if (_draggedItem.ParentItemsControl != targetDropItem.ParentItemsControl)
            {
                e.Cancel = true;
                return;
            }
        }
Reply
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.