Answered by:
How to implement drag&drop with multiple selected ListViewItems simultaneously

Question
-
Hi,guys,Merry Christmas!
I want to allow user selected multiple ListViewItems and drag them to somewhere else in a Windows store app. I have done some online searching and find a solution:http://social.msdn.microsoft.com/Forums/vstudio/en-US/25530928-6fc5-4ec7-9101-38ddbbad18c8/listviewlistbox-multiple-item-selection-drag-and-drop-example?forum=wpf. But the problem is it's for WPF, and WinRT has no PreviewMouseLeftButtonDown event any more.
So my question is what's the equivalent even in WinRT? If there is no such event, then how to implement such function?
Best reguards!
Wednesday, December 25, 2013 12:58 AM
Answers
-
Hi, James, thanks for the quick reply in holiday! FYI, I want to implement a gesture which would allow user drag the selected ListViewItems outside of the ListView and then delete/remove them on drop as I've mentioned in this thread(http://social.msdn.microsoft.com/Forums/windowsapps/en-US/8a3055e4-5ad6-46d2-a802-1ae36eeb63f7/drag-an-item-out-of-listview-and-then-delete-it-when-droped?forum=winappswithcsharp).
After I've post the thread, I found that ListView does support drag&drop of multiple selected items. In fact, one can access the multiple dragged items using Items property of DragItemsStartingEventArgs in the DragItemsStarting event. And the gesture also works very well. Sorry! That's my fault for forgetting to update the thread accordingly.
However, I've to mention that the drag animation when dragging multiple selected items is quite not as expected: Instead to move the images of the multiple selected items being dragged simultaneously, it only show the image of the item on which the pointer is pressed, while other items just "disappear" and blank spaces were left where they used to be.
Probably the animation is just by design. Although sometimes this designation maybe a little confusing, it is acceptable and quite do the job.
Best regards!
EDIT:In fact, the gesture will crash if we delete the dragged items, to make it work I have to hide them instead of deleting them.The issue is like what I post in this thread: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/0c300b72-e425-44e7-889e-968bf3d1168d/listview-crashed-when-deleting-dragged-item?forum=winappswithcsharp
- Edited by silverbird.lee Thursday, December 26, 2013 11:41 AM
- Marked as answer by Jamles HezModerator Friday, December 27, 2013 8:13 AM
Thursday, December 26, 2013 10:36 AM
All replies
-
Hi sliverbird
Merry Christmas, I don't think WinRT has such feature.
But I'm not quite understand why you need PreviewMouseLeftButtonDown event while drag the listview item, is there something over these items? Normally use drag and drop can help you. Can I know the detail scenario of your problem?
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Thursday, December 26, 2013 9:35 AMModerator -
Hi, James, thanks for the quick reply in holiday! FYI, I want to implement a gesture which would allow user drag the selected ListViewItems outside of the ListView and then delete/remove them on drop as I've mentioned in this thread(http://social.msdn.microsoft.com/Forums/windowsapps/en-US/8a3055e4-5ad6-46d2-a802-1ae36eeb63f7/drag-an-item-out-of-listview-and-then-delete-it-when-droped?forum=winappswithcsharp).
After I've post the thread, I found that ListView does support drag&drop of multiple selected items. In fact, one can access the multiple dragged items using Items property of DragItemsStartingEventArgs in the DragItemsStarting event. And the gesture also works very well. Sorry! That's my fault for forgetting to update the thread accordingly.
However, I've to mention that the drag animation when dragging multiple selected items is quite not as expected: Instead to move the images of the multiple selected items being dragged simultaneously, it only show the image of the item on which the pointer is pressed, while other items just "disappear" and blank spaces were left where they used to be.
Probably the animation is just by design. Although sometimes this designation maybe a little confusing, it is acceptable and quite do the job.
Best regards!
EDIT:In fact, the gesture will crash if we delete the dragged items, to make it work I have to hide them instead of deleting them.The issue is like what I post in this thread: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/0c300b72-e425-44e7-889e-968bf3d1168d/listview-crashed-when-deleting-dragged-item?forum=winappswithcsharp
- Edited by silverbird.lee Thursday, December 26, 2013 11:41 AM
- Marked as answer by Jamles HezModerator Friday, December 27, 2013 8:13 AM
Thursday, December 26, 2013 10:36 AM -
Hi silverbird,
It seems you have solve the problem you asked in this post and I will mark your reply as answer. By the way, I will deliver the animation suggestion to our senior engineer as a customer wish.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Friday, December 27, 2013 8:12 AMModerator -
Jamles, thanks!
BTW: Although the question in the first post of this thread has been "solved" by myself, I still have problem with the delete-on-drop gesture. The problem is if user delete the items being dragged, the app will crash, so I have to hide them instead of deleting them. This seems a nice work-ground, but I have to change the view model to make it work. So I really want to know if there is a "direct" solution. It seems a very common feature for allowing user to drag selected items and delete them when dropping them outside the ListView. So it would be great if we have a clean solution for this.
Here is my first thought about the reason why this gesture will crash the app: When items are dragged out of the ListView(or other ItemsControl), the system is expecting them to return back to the same ListView. So if they are removed, then the system will not be able to get them back, thus cause runtime exception which crash the whole app.
I don't know if there are many people who want this gesture, but I honestly think there very touch-friendly.
Best regards!
[EDIT]
Hi, Jamles! I finally found the solution for implementing delete-on-drop gesture: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/0c300b72-e425-44e7-889e-968bf3d1168d/listview-crashed-when-deleting-dragged-item?forum=winappswithcsharp.
In fact, the solution for this is quite simple, I just made simple things over-complicated. I am sorry for all the possible confusion and mass I made on this issue. And thanks again for deliver the animation suggestion!
- Edited by silverbird.lee Friday, December 27, 2013 2:18 PM
Friday, December 27, 2013 9:49 AM