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

Multiple row drag and drop between gridviews

13 Answers 172 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Johannes asked on 15 Jan 2013, 12:07 PM
Hi,
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!

:)

//JaggenSWE

13 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 16 Jan 2013, 02:42 PM
Hi,

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. 
 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Johannes
Top achievements
Rank 1
answered on 16 Jan 2013, 03:46 PM
Hi Didie,
thanks for that tip. I'll give it a try and will be back here if I have any questions. :)
0
Johannes
Top achievements
Rank 1
answered on 21 Jan 2013, 11:10 AM
Hi again, I really can't seem to get the hang of it.. I have the following code (as per the example, with some minor modifications).
How do I change this to be able to make Drag'n'Drop for multiple rows at a time???
private void Grid_DropQuery(object sender, Telerik.Windows.Controls.DragDrop.DragDropQueryEventArgs e)
{
    var row = e.Options.Source as GridViewRow;
    var destinationGrid = e.Options.Destination as RadGridView;
 
    e.QueryResult = row != null && row.GridViewDataControl != null && destinationGrid != null && row.GridViewDataControl != destinationGrid;
}
 
private void Grid_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e)
{
    var destinationGrid = e.Options.Destination as RadGridView;
    string dest = e.Options.Destination.Name;
 
    if (e.Options.Status == Telerik.Windows.Controls.DragDrop.DragStatus.DropComplete && destinationGrid != null)
    {
        if (dest == "rgV1")
        {
            rUser d = (rUser)e.Options.Payload;
 
            dataHolder.gv1Data.Add(new User
            {
                Id = d.Id,
                Active = d.Active,
                Approved = d.Approved,
                LastLoginDate = d.LastLoginDate,
                Route = "",
                UserName = d.UserName
            });
 
            rgV1.ItemsSource = dataHolder.gv1Data;
 
            dataHolder.gv2Data.Remove(d);
        }
    }
}
 
private void Grid_DragInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e)
{
    var sourceRow = e.Options.Source as GridViewRow;
 
    if (e.Options.Status == Telerik.Windows.Controls.DragDrop.DragStatus.DragComplete && sourceRow != null)
    {
        ((IList)sourceRow.GridViewDataControl.ItemsSource).Remove(e.Options.Payload);
    }
}
0
Nick
Telerik team
answered on 23 Jan 2013, 03:05 PM
Hello Johannes,

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! 

All the best,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Johannes
Top achievements
Rank 1
answered on 24 Jan 2013, 01:59 PM
Hi Nik,

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.

//Johannes
0
Nick
Telerik team
answered on 24 Jan 2013, 02:18 PM
Hi Johannes,

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! 

Kind regards,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Leonid
Top achievements
Rank 1
answered on 05 Jul 2015, 12:57 PM

Hello,

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.

Thanks !

0
Dimitrina
Telerik team
answered on 08 Jul 2015, 10:06 AM
Hello,

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?

Regards,
Dimitrina
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
Raphael
Top achievements
Rank 1
answered on 10 Jan 2019, 12:51 PM

Hello,

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?

0
Martin Ivanov
Telerik team
answered on 15 Jan 2019, 12:27 PM
Hi Raphael,

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. 

Regards,
Martin Ivanov
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
Raphael
Top achievements
Rank 1
answered on 15 Jan 2019, 03:24 PM

Hi Martin,

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

<telerik:RadGridView x:Name="Grid"
    SelectionMode="Extended"
    DragElementAction="Select"

And I can DragAndDrop Items using Behavior similiar to Reorder Rows demo using RadGridView MyBehaviorNamespace.CustomBehavior.IsEnabled="True"

<telerik:RadGridView x:Name="Grid"
    SelectionUnit="FullRow"
    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 :)

0
Raphael
Top achievements
Rank 1
answered on 15 Jan 2019, 03:30 PM

[quote]Raphael said:

...

MyBehaviorNamespace.CustomBehavior.IsEnabled="True"

<telerik:RadGridView x:Name="Grid"
    SelectionUnit="FullRow"
    myBehaviorNamespace:CustomBehavior.IsEnabled="True"

[/quote]

Forgot to mention that I also configured DragNDrop on Rows for the second functionality

<telerik:RadGridView.RowStyle>
    <Style TargetType="telerik:GridViewRow">
        <Setter Property="telerik:DragDropManager.AllowDrag" Value="True" />
    </Style>
</telerik:RadGridView.RowStyle>
0
Martin Ivanov
Telerik team
answered on 18 Jan 2019, 11:46 AM
Hello Raphael,

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.

Regards,
Martin Ivanov
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.
Tags
GridView
Asked by
Johannes
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Johannes
Top achievements
Rank 1
Nick
Telerik team
Leonid
Top achievements
Rank 1
Raphael
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or