This is a migrated thread and some comments may be shown as answers.

Desactivate drop on root level

1 Answer 33 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
ATHOME
Top achievements
Rank 1
ATHOME asked on 07 Jul 2014, 04:39 PM
I have several treeviews generated by a ItemsControl, and I'd like to disable the ability to drop an element on the root level. (Basically, you can reorder subtrees, but you can't create a new root).

I tried attaching an event to drag and drop of the tree view like that 

 for (int i = 0; i < Trees.Items.Count; i++)
            {
                var uiElement =
                    (ContentPresenter)Trees.ItemContainerGenerator.ContainerFromIndex(i);
                if (uiElement == null)
                    continue;
                RadTreeView dependencyObject = VisualTreeHelper.GetChild(uiElement,0) as RadTreeView;
                
                DragDropManager.AddDragOverHandler(dependencyObject,OnDragOver,true);
                DragDropManager.AddDragInitializeHandler(dependencyObject,OnDragInit,true);
            }

But the event does not seem to fire. 

Any hint on how to achieve what I want ?

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 09 Jul 2014, 08:54 AM
Hello,

I tested your code but I wasn't able to reproduce the behavior where the events doesn't fire. Can you please double check that you have set the IsDragDropEnabled property of the RadTreeView to true? I also attached a sample project, can you please give it a try and let me know if I am missing something?

As for forbidding drop on specific RadTreeViewItem you can set the item's IsDropAllowed property to false. This property indicates whether the tree item can accept data that the user drags onto it.

In addition you can take a look at the Drag and Drop and the Disable Drop at Specific Location help articles.

Please let me know if you need any further assistance.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
TreeView
Asked by
ATHOME
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or