How to disable the dropping of an node next to the root node of my TreeView?

2 posts, 0 answers
  1. koala
    koala avatar
    7 posts
    Member since:
    Apr 2015

    Posted 24 Sep 2015 Link to this post


    I'm using the RadTreeView with only ONE root node. My ItemsSource is FolderData. FolderData has only one Item - the root node. I'm using

    DragDropManager.AddDragOverHandler(this.FolderRadTreeView, new Telerik.Windows.DragDrop.DragEventHandler(OnDragOver), true);

    ​ for allowing the dropping in special nodes. 


    How can I disable the dropping next to root node? I want to avoid to have more than one root nodes. Is it possible?

  2. Peshito
    Peshito avatar
    585 posts

    Posted 29 Sep 2015 Link to this post


    You can prevent your items from being dropped outside the root node by implementing OnDragOver like shown bellow for instance:
    private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
                var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
                if (options != null)
                    if (options.DropTargetItem.Header.ToString() == "Sport Categories" && options.DropPosition != DropPosition.Inside)
                        options.DropAction = DropAction.None;
                        options.DropPosition = DropPosition.Undefined;
    The important thing here is that you should change the DropAction and DropPosition depending on the DropTargetItem.

    Attached is a sample project illustrating the above approach.

    Hope it helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top