Desactivate drop on root level

2 posts, 0 answers
  1. ATHOME
    ATHOME avatar
    1 posts
    Member since:
    Jun 2014

    Posted 07 Jul 2014 Link to this post

    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 ?

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 09 Jul 2014 Link to this post

    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.
     
  3. DevCraft banner
Back to Top