I've had a look at the Wpf-AutoDrag project which I found at this forum.
I've adjusted it to fit my wishes and all is find and dandy, BUT, how on
earth do I enable drag and drop for MULTIPLE rows? Right now I can
only move the rows one by one, which can be a tedious task if you need
to move like 50 rows every time. :(
I guess there's a simple solution to this issue, however I've still to find it, please help!
13 Answers, 1 is accepted
Actually you can easily extend the example for a single row to achieve your goal. To do so you can check what the SelectedItems of the source GridView are and then set them to your DragPayload. Later you can loop through them and add the SelectedItems to the target GridView.
the Telerik team
thanks for that tip. I'll give it a try and will be back here if I have any questions. :)
How do I change this to be able to make Drag'n'Drop for multiple rows at a time???
I can see that you have taken the approach with the RadDragAndDropManager. This Mechanism has been obsoleted and we strongly recommend the usage of our new mechanism - DragDropManager.
You can see an example of its usage within the GridView here(the same example is available in your local copy of our controls).
To be able to Drag and Drop multiple items, you have to do a couple of things.
First, the GridView has to have its selection mode set to either Multiple or Extended.
Second, you have to modify the DragDropEvents to use the SelectedItems property of the GridVeiw instead of the SelectedItem property, thus you will be able to drag all the selected items rather than the initial one.
Let me know if you still have any issues with the approach!
the Telerik team
I've gone over that example a couple of times as well, but how do I customize it to handle MORE than one row?
If, let's say, I wanted to move 5 rows from grid 1 to grid 2 (or reorder them), how would I approach that? Right now
it references a GridViewRow, which seems to imply that it only care about ONE single row.
In this case, as I pointed out in my previous reply, you have to use the SelectedItems property. The idea is to loop through the selected items and make a copy of the Collection, which you can set as DraggedData. Later on(OnDrop/DragDropCompleted/etc.), you can get the collection you have created and process the necessary events.
Hope this makes sense!
the Telerik team
Can you please give us an example of Reorder rows by drag and drop but with multiple rows selection?
I tried to change your DEMO code (reorder rows) but with no success.
As it turns out we do not have such an exact example.
Following the Reorder Rows example, in order to drag and drop multiple rows you have to loop through the selected items of the source RadGridView and save information on all the dragged items with dragPayload on DragInitialize (through DropIndicationDetails). Basically, you should replace the CurrentDraggedItem property with the collection of items being dragged. Then, get the saves details on drop to proceed further.
Do you experience any specific issue with this?
I'm trying to implement the very same scenario.
I'm using MultiSelection with SelectionMode=Extended and the DragDropBehavior with DragDropManager behind.
When creating a multiselection I'm using drag-functionality as well (which is support in Extended-Mode by default).
But using both together does not work. I'm not able to use the draggable multiselection and DragNDrop.
How can I combine both functionalities?
The custom Reorder Rows demo is implemented to work in a scenario with a single selection. Actually, the behavior doesn't use the selection at all. Instead it gets the row under the mouse and works with it. If you want to make the demo work when selecting multiple items you will need to alter the implementation of the behavior.
Basically, you can find where the drag operation initializes (DragInitialize event) and replace the logic that passes the dragged item to the drag/drop operation (using e.Data of the event arguments). There you can get all the selected items from the SelectedItems property of RadGridView and give them to the drag/drop operation. Then you will also need to modify the logic in the Drop event in order to get all the dragged items and add them in the ItemsSource of the corresponding RadGridView instance.
thanks for providing details regarding my question.
I already implemented your suggestions via SelectedItems in the DragInitialize and Drop methods.
My problem is different. I want to enable draggable selection together with using DragAndDrop functionality.
I can create a multiselection via mouse using RadGridView.SelectionMode and DragElementAction
And I can DragAndDrop Items using Behavior similiar to Reorder Rows demo using RadGridView MyBehaviorNamespace.CustomBehavior.IsEnabled="True"
But I'm not able to find a way to use both functionalities in one and the same Grid.
I'm happy about any hint :)
Forgot to mention that I also configured DragNDrop on Rows for the second functionality
Thank you for the additional information. The custom drag/drop behavior is capturing the mouse which cancels the built-in drag-to-select behavior. Both behaviors cannot co-operate because their events are colliding, but I can suggest you couple of options that should allow you to achieve your requirement.
- The first option is to allow the drag-to-select (via the DragElementAction) only if you press some special key. For example a Ctrl, or Alt, or whatever you prefer. When you do this you can set the DragElementAction property to Select and the drag/drop behavior's IsEnabled to False (or the AllowDrag to False). I've updated the Reoder Rows demo to show this approach. While holding the left Alt key, the drag/drop behavior is disabled and the DragElementAction is enabled. I hope it helps.
- The second approach is to implement a custom drag-to-select logic using custom attached behavior (like with the row reorder behavior). However, this will require to implement it from scratch.