Drag drop to item in ListView

5 posts, 0 answers
  1. Thomas Bargholz
    Thomas Bargholz avatar
    14 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 | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4129 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. Michael
    Michael avatar
    10 posts
    Member since:
    Dec 2012

    Posted 01 Feb 2020 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello,

    How do you get the entire row from a cell? Right now I'm looping through the items and seeing if the item I'm on has a string that matches what was returned in "droppedItem" in your example. I'm guessing there's a much better way to do that. .

    The idea is that any time I right click one of my listviews(they're all in detail view), I store the entire row in a class that I use in other places. 

    Thanks in advance!

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4129 posts

    Posted 03 Feb 2020 Link to this post

    Hello, Michael,   

    You can access the target ListViewDataItem via the DetailListViewDataCellElement.Row property. Once you have the data item, you can get the value of any cells in this item or any information that is stored in the Tag

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Michael
    Michael avatar
    10 posts
    Member since:
    Dec 2012

    Posted 03 Feb 2020 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you, Dess! I'm all set.
Back to Top