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

Drag-Drop from RadTreeView to custom control

1 Answer 146 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
PLuS
Top achievements
Rank 1
PLuS asked on 04 May 2015, 08:24 AM

Hi,

I have a RadTreeView with some items inside and want to drag and drop items to a custom control derived from RadControl (which is inside a DocumentWindow in a RadDock).

I tried to attach TreeViewElement.DragDropService.PreviewDragOver event but it does not fire for my custom control. (Have set AllowDrop to true and tried to implement ISupportDrop interface but no luck)

Any help would be appreciated.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 May 2015, 01:06 PM
Hello Omid,

Thank you for writing.

RadTreeView controls the drag and drop functionality by TreeViewDragDropService. The RadTreeView.AllowDragDrop property should be set to true along with the drop target's AllowDrop property. If the custom control is a derivative of RadControl, the TreeViewDragDropService will search for an RadElement which is ISupportDrop. However, the RadControl is a basic class that does not have such an element. You can add a LightVisualElement or derive from another control, e.g. RadPanel.
CustomControl c = new CustomControl();
 
public Form1()
{
    InitializeComponent();
 
    c.BackColor = Color.Red;
    this.splitPanel2.Controls.Add(c);
    c.Size = new System.Drawing.Size(100, 100);
 
    this.radTreeView1.AllowDragDrop = true;
    this.radTreeView1.TreeViewElement.DragDropService.PreviewDragOver += DragDropService_PreviewDragOver;
    this.radTreeView1.TreeViewElement.DragDropService.PreviewDragDrop += DragDropService_PreviewDragDrop;
}
 
private void DragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
{
    LightVisualElement lve = e.HitTarget as LightVisualElement;
    if (lve == null)
    {
        return;
    }
    CustomControl c = lve.ElementTree.Control as CustomControl;
    if (c != null)
    {
        c.BackColor = Color.Yellow;
    }
}
 
private void DragDropService_PreviewDragOver(object sender, Telerik.WinControls.RadDragOverEventArgs e)
{
    e.CanDrop = false;
    if (!(e.HitTarget is TreeNodeElement || e.HitTarget is RadTreeViewElement))
    {
        e.CanDrop = true;
    }
}
 
public class CustomControl : RadControl
{
    protected override void CreateChildItems(RadElement parent)
    {
        base.CreateChildItems(parent);
        LightVisualElement lve = new LightVisualElement();
        lve.AllowDrop = true;
        parent.Children.Add(lve);
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Treeview
Asked by
PLuS
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or