Drag And Drop

2 posts, 0 answers
  1. Pablo Tola
    Pablo Tola avatar
    43 posts
    Member since:
    Nov 2007

    Posted 14 Feb 2011 Link to this post

    I want to prevent dragging items to the same level as the root, how do I do this?

  2. Petar Mladenov
    Petar Mladenov avatar
    2882 posts

    Posted 17 Feb 2011 Link to this post

    Hello Pablo Tola,

    Imagine a RadTreeView's rootlevel is bound to a collection of CategoryViewmodels. You can use the RadDragDropManager's  OnDrop event  to prevent dropping an item in the root level when you drag an item below the tree items. On the other hand, you have to use the PreviewDragEnded event of the RadTreeView in order to prevent dropping before and after a rootlevel item. Please check out this code and let me know how it goes on your side.
    public MainPage()
               this.DataContext = new TreeViewViewModel();
               this.treeView.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);
               this.treeView.AddHandler(RadDragAndDropManager.DragQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDragQuery), true);
               this.treeView.PreviewDragEnded += new RadTreeViewDragEndedEventHandler(TreeView_PreviewDragEnded);
               this.treeView.DragOverTree += new DragOverTreeEventHandler(TreeView_DragOverTree);
           void TreeView_PreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
               if (e.TargetDropItem.Item is CategoryViewModel)
                   if (e.DropPosition == DropPosition.After ||
                       e.DropPosition == DropPosition.Before)
                       e.Handled = true;
           // OnDropQuery event handler
           private void OnDropQuery(object sender, DragDropQueryEventArgs e)
               if (e.Options.Destination == this.treeView)
                   e.QueryResult = false;

    Petar Mladenov
    the Telerik team
  3. DevCraft R3 2016 release webinar banner
Back to Top