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

Drag drop to item in ListView

4 Answers 170 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Thomas Bargholz
Top achievements
Rank 1
Iron
Thomas Bargholz asked on 05 Aug 2015, 01:10 PM

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

 

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Aug 2015, 12:45 PM
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
0
Michael
Top achievements
Rank 1
Veteran
answered on 01 Feb 2020, 08:05 PM

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!

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Feb 2020, 11:06 AM
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.
0
Michael
Top achievements
Rank 1
Veteran
answered on 03 Feb 2020, 06:34 PM
Thank you, Dess! I'm all set.
Tags
ListView
Asked by
Thomas Bargholz
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Michael
Top achievements
Rank 1
Veteran
Share this question
or