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

Prevent from removing a node after a drop

1 Answer 37 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Stéphane
Top achievements
Rank 1
Stéphane asked on 16 Jan 2014, 12:49 PM
Hi,

I upgraded from version 2012.3.1129.40 to 2013.3.1204.40.
With this new version I didn't find how to prevent from removing a node after drag & drop.
In the older version I was able to do it with:
public MyView()
{
  InitializeComponent();
  this.m_cellTreeView.PreviewDragEnded += this.OnPreviewDragEnded;
}
  
private void OnPreviewDragEnded(object sender, RadTreeViewDragEndedEventArgs e)
{
  e.Handled = true;
}

With the new version, I'm using your recommendations: I use the DragDropManager class only, I set the DragDropExecutionMode to New but the PreviewDragEnded handler is not called anymore and the event PreviewDragEnded is marked as deprecated.
What is the best way to do this ?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 20 Jan 2014, 05:29 PM
Hello St├ęphane,

I have created a sample project for you which demonstrates how to use the RadTreeView's drag & drop functionality to Copy items. In the example we can only copy people between the two RadTreeViews.
This is achieved by overriding the DragDropManager's DragOver event on the TreeViews:
DragDropManager.AddDragOverHandler(this.xTree1, new Windows.DragDrop.DragEventHandler(OnDragOver), true);
DragDropManager.AddDragOverHandler(this.xTree2, new Windows.DragDrop.DragEventHandler(OnDragOver), true);
private static void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
            if (options != null)
            {
                var isDraggingGroups = options.DraggedItems.OfType<Group>().Count() > 0;
                if (isDraggingGroups)
                {
                    //// Disable drop of groups.
                    options.DropAction = DropAction.None;
                    options.UpdateDragVisual();
                }
                else
                {
                    var dropGroup = GetDropGroup(options);
                    if (dropGroup == null)
                    {
                        //// Disable drop in leaf items.
                        options.DropAction = DropAction.None;
                        options.UpdateDragVisual();
                    }
                    else
                    {
                        //// Override drop in Groups to be always Drop Inside.
                        options.DropPosition = Telerik.Windows.Controls.DropPosition.Inside;
                        options.DropAction = DropAction.Copy;
                        options.UpdateDragVisual();
                    }
                }
            }
        }

In order to copy an item we have to set the TreeViewDragDropOptions's property DropAction to Copy (the DropAction enumeration defines the following actions Copy, Delete, Move or None).

You can find more information on the RadTreeView's Drag and Drop feature in our documentation under the How To  section (under "Drag and Drop" folder).

Please let me know if this sample meets your requirement.

Regards,
Boris Penev
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
TreeView
Asked by
Stéphane
Top achievements
Rank 1
Answers by
Boris
Telerik team
Share this question
or