List View Item to Document window.

4 posts, 0 answers
  1. Hugues
    Hugues avatar
    54 posts
    Member since:
    Sep 2014

    Posted 17 Oct 2014 Link to this post

    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.
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 22 Oct 2014 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Hugues
    Hugues avatar
    54 posts
    Member since:
    Sep 2014

    Posted 24 Oct 2014 in reply to Dess Link to this post

    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.
  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 29 Oct 2014 Link to this post

    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.

     
Back to Top