Multiple row drag and drop between gridviews

9 posts, 0 answers
  1. Johannes
    Johannes avatar
    16 posts
    Member since:
    Nov 2012

    Posted 15 Jan 2013 Link to this post

    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
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 Jan 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Johannes
    Johannes avatar
    16 posts
    Member since:
    Nov 2012

    Posted 16 Jan 2013 Link to this post

    Hi Didie,
    thanks for that tip. I'll give it a try and will be back here if I have any questions. :)
  5. Johannes
    Johannes avatar
    16 posts
    Member since:
    Nov 2012

    Posted 21 Jan 2013 Link to this post

    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);
        }
    }
  6. Nick
    Admin
    Nick avatar
    593 posts

    Posted 23 Jan 2013 Link to this post

    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.

  7. Johannes
    Johannes avatar
    16 posts
    Member since:
    Nov 2012

    Posted 24 Jan 2013 Link to this post

    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
  8. Nick
    Admin
    Nick avatar
    593 posts

    Posted 24 Jan 2013 Link to this post

    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.

  9. Leonid
    Leonid avatar
    2 posts
    Member since:
    Feb 2012

    Posted 05 Jul 2015 Link to this post

    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 !

  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Jul 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready