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

Treeview Copy and Drop rather than Drag and Drop

2 Answers 127 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 2
Andrew asked on 11 May 2012, 06:50 PM
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 Answers, 1 is accepted

Sort by
0
Andrew
Top achievements
Rank 2
answered on 12 May 2012, 11:49 AM
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
0
Svett
Telerik team
answered on 16 May 2012, 02:23 PM
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 >>
Tags
Treeview
Asked by
Andrew
Top achievements
Rank 2
Answers by
Andrew
Top achievements
Rank 2
Svett
Telerik team
Share this question
or