Prevent from removing a node after a drop

2 posts, 0 answers
  1. Stéphane
    Stéphane avatar
    6 posts
    Member since:
    Mar 2012

    Posted 16 Jan 2014 Link to this post

    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,
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 20 Jan 2014 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top