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

List View Item to Document window.

3 Answers 70 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Hugues
Top achievements
Rank 1
Hugues asked on 17 Oct 2014, 05:52 PM
I have dragdrop enable on both controls. But i whenever i try to drag an item from the list view over to the document window, it shows the red circle that tells me it cannot drop the object. So i went down the route of implementing PreviewDragDrop to get it working, but then i have no clue how to get the handle of my document window since preview drag and drop is giving me back an RadPageViewTabStripElement and none of the item in there matches a Document window.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Oct 2014, 08:12 AM
Hello Hugues,

Thank you for writing.

RadListView supports RadDragDropService which is purposed to allow you customize the drag and drop functionality. You can find quite useful examples on this topic in our ListView online documentation >> Drag and drop section.

Pay attention to the Drag and Drop using RadDragDropService help article. Here is a sample approach how to allow dragging over the DocumentWindow:
public Form1()
{
    InitializeComponent();
 
    this.radListView1.Columns.Add("Id");
    this.radListView1.Columns.Add("Title");
    this.radListView1.ViewType = ListViewType.DetailsView;
    this.radListView1.AllowDragDrop = true;
    List<string> products = new List<string>()
    {
        "Telerik UI for WinForms",
        "Telerik UI for Silverlight",
        "Telerik UI for WPF",
        "Telerik UI for ASP.NET AJAX"
    };
    for (int i = 0; i < products.Count; i++)
    {
        ListViewDataItem item = new ListViewDataItem();
        this.radListView1.Items.Add(item);
        item["Id"] = Guid.NewGuid().ToString();
        item["Title"] = products[i];
    }
 
    this.radListView1.ListViewElement.DragDropService.PreviewDragOver+=DragDropService_PreviewDragOver;
    this.radListView1.ListViewElement.DragDropService.PreviewDragDrop+=DragDropService_PreviewDragDrop;
}
 
private void DragDropService_PreviewDragOver(object sender, RadDragOverEventArgs e)
{
    RadPageViewTabStripElement tabStrip = e.HitTarget as RadPageViewTabStripElement;
    if (tabStrip!=null)
    {
            e.CanDrop = this.documentTabStrip1.TabStripElement == tabStrip;
    }        
}
 
private void DragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
{
    BaseListViewVisualItem draggedItem = e.DragInstance as BaseListViewVisualItem;
 
    //TO DO drop action
 
    this.radListView1.Items.Remove(draggedItem.Data);
}

Feel free to extend the PreviewDragDrop event handler on a way to achieve the desired behavior.

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

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Hugues
Top achievements
Rank 1
answered on 24 Oct 2014, 07:39 PM
Thanks. I also have another question regarding PreviewDragOver. I put an DebugPrint statement in there to check the types which i am dragging over. It seems to me that for some controls when i dragged over them PreviewDragOver does not get executed. One of the thing i am trying to do is drag a drop and Item From ListView to an button that is located inside a ScrollablePanel.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Oct 2014, 03:39 PM
Hello Hugues,

Thank you for writing back.

In order to fire the PreviewDragOver event, note that the target element should allow the drop operation. Hence, its AllowDrop property should be set to true. If you have a RadButton and your requirement is to enable dragging over it, you should set the ButtonElement.AllowDrop property to true.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

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