Drag drop to item in ListView

2 posts, 0 answers
  1. Thomas Bargholz
    Thomas Bargholz avatar
    7 posts
    Member since:
    Oct 2006

    Posted 05 Aug 2015 Link to this post

    Hi,

    I have a solution where a user ​drags data into my application, onto a RadListView. The user drops the data on top of a RadListViewItem representing the subject to added the data to. I have added code for detecting which item that ​was dropped on (from Telerik documentation), but it always returns null from GetElementAtPoint. I have tried other Points (screen, control, client), but it's allways null.

    The RadListView is unbound, in DetailView mode and have an icon and two columns. I don't know if that makes any difference in how this is handled.

    private void radListView1_DragDrop(object sender, DragEventArgs e)
    {
        Point point = radListView1.PointToClient(new Point(e.X, e.Y));
        BaseListViewVisualItem droppedItem = radListView1.ElementTree.GetElementAtPoint(point) as BaseListViewVisualItem;
        if (droppedItem != null)
        {
            ListViewDataItem item = droppedItem.Data;
               // handle dropped data here
        }
    }
     

    I am using Telerik version 2014.1.226.40.

    Best regards

    Thomas

     

  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 06 Aug 2015 Link to this post

    Hello Thomas,

    Thank you for writing.

    When you use ListViewType.DetailsView, you have data cells, no visual items. Please refer to the following code snippet:
    private void radListView1_DragDrop(object sender, DragEventArgs e)
    {
        Point point = radListView1.PointToClient(new Point(e.X, e.Y));
        DetailListViewDataCellElement targetCell = radListView1.ElementTree.GetElementAtPoint(point) as DetailListViewDataCellElement;
        if (targetCell != null)
        {
            
        }
    }

    The ListView >> Drag and Drop section in our online documentation is quite useful on this topic. 

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top