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

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

1 Answer 222 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
koala
Top achievements
Rank 1
koala asked on 24 Sep 2015, 04:09 PM

Hello,

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?

1 Answer, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 29 Sep 2015, 01:03 PM
Hi,

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;
                    options.UpdateDragVisual();
                }
            }           
        }
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.

Regards,
Peshito
Telerik
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
Tags
TreeView
Asked by
koala
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Share this question
or