Treeview Copy and Drop rather than Drag and Drop

3 posts, 0 answers
  1. Andrew
    Andrew avatar
    2 posts
    Member since:
    Jun 2012

    Posted 11 May 2012 Link to this post

    Hi 

    I have an initial treeview with 12 root nodes.  I am using the default capabilities of treeview to drag and arrange these nodes into a second treeview..  Everything works sweetly except that of course the nodes in the original treeview are no longer present after the drag process.  

    What I'd really like to do is drag a copy of the original node and leave the original available to be used again.  I am actually building a series of steps in the form of a treeview and each step may be used multiple times.

    I tried implementing the ItemDrag and DragDrop etc. events myself and that just caused the entire treeview to lock up with cascading events in much the same way as another message here describes.

    Is there a simple way to generate the modality that I need?

    Regards
    ~A
  2. Andrew
    Andrew avatar
    2 posts
    Member since:
    Jun 2012

    Posted 12 May 2012 Link to this post

    Resolved - sort of.

    I hooked in the DragEnded event and used this to Insert an identical new node at the same index of the original one.

    If there's a better solution then I'd still like to hear about it.

    ~A
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Svett
    Admin
    Svett avatar
    728 posts

    Posted 16 May 2012 Link to this post

    Hi Andrew,

    Thank you for writing/

    In our latest release, we provided a convenient mechanism for altering this behavior. To do that create a inheritor of TreeViewDragDropService and override its IsCopyingNodes property:
    public class CustomTreeViewDragDropService : TreeViewDragDropService
    {
        public CustomTreeViewDragDropService(RadTreeViewElement treeView)
            : base(treeView)
        {
     
        }
     
        protected override bool IsCopyingNodes
        {
            get
            {
                return true;
            }
        }
    }

    Then you should create a custom RadTreeViewNodeElement and RadTreeView control in order to replace the default tree view drag and drop behavior:
    public class CustomRadTreeViewElement : RadTreeViewElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadTreeViewElement);
            }
        }
     
        protected override TreeViewDragDropService CreateDragDropService()
        {
            return new CustomTreeViewDragDropService(this);
        }
    }

    public class CustomRadTreeView : RadTreeView
    {
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadTreeView).FullName;
            }
            set
            {
                base.ThemeClassName = value;
            }
        }
     
        protected override RadTreeViewElement CreateTreeViewElement()
        {
            return new CustomRadTreeViewElement();
        }
    }

    Please note that this is possible only in Q1 2012 SP1 (2012.1 321) and on.

    I hope this helps.

    Kind regards,
    Svett
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top