DropHandler Drag & Drop fro Grid to Grid

9 posts, 0 answers
  1. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 13 Jun 2012 Link to this post

    Hi,

    i'm using two RadGridViews with one MVVM (ObservableCollection<foptxt>()). With Drag and Drop i moove the items from GridA to GridB.

    How do i add a DropHandler for the dropped items? I just found an example for a Listbox, but i can't change this to run with a GridView.

    Thanks
    Best Regards
    Rene
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Jun 2012 Link to this post

    Hi Rene,

     I would recommend you to check this help article about drag and drop from ListBox to RadGridView. Here you can find information about all the dragdrop events.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 13 Jun 2012 Link to this post

    Hi,

    thanks but this doesn't help so much. Drag works fine. But drop does not work, the item away after dropping it.
    FoptxtQuelle.ItemsSource = ITA_Packetverwaltung.Model.Foptxt.foptxt.GetFopTXT(ziel_s);
    RadDragAndDropManager.AddDropInfoHandler(this.FoptxtZiel, DestinationBox_DropInfo);
    FoptxtZiel.ItemsSource = ITA_Packetverwaltung.Model.Foptxt.foptxt.GetFopTXTDB(Properties.Settings.Default.AKTPaketnr);
     
    does not start the "DestinationBox_DropInfo when the item ist dropped. There is no error, but the void will not start.

    RadGridView:

     

    <telerik:RadGridView Name="FoptxtZiel" Margin="0" RowIndicatorVisibility="Collapsed" IsReadOnly="True" RowHeight="30" Grid.Row="1"
    telerik:StyleManager.Theme="Metro" Width="Auto" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="True" AlternateRowBackground="#a0d9f3" ItemsSource="{Binding}" telerik:RadDragAndDropManager.AllowDrop="True">

    Why does the DestinationBox_DropInfo does not start?

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 Jun 2012 Link to this post

    Hi Rene,

     I have prepared a sample project to show you how you could implement row reordering between/within two GridViews using RadDragAndDropManager.

    Please check the attached solution for a reference.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 15 Jun 2012 Link to this post

    Hi,

    thank's a lot, there ist still a little Problem the Dragged Item will not be remooved from the SourceGrid. I found this in your
    example:
    private int RemoveDraggedItems(IList sourceList, IEnumerable<object> draggedItems, int currentDropIndex)
      {
            var newDropIndex = UpdateDropIndex(draggedItems, sourceList, currentDropIndex);
            foreach (var itemToRemove in draggedItems)
               sourceList.Remove(itemToRemove);
           return newDropIndex;
       }

    But the Item will not be remooved from the sourcelist. Why?
    Thanks rene
  7. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 15 Jun 2012 Link to this post

    Hi,

    the Problem is solved, thanks so much. But one more question in this case. Is it possible to check if the dragged item is already in the target GridView? If the Item is already there the drop should cancel.

    thanks
    best regards
    rene
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Jun 2012 Link to this post

    Hi,

     When the OnDropInfo method is raised you could check if the draggedItem is contained in the destination GridView. You have the draggedItems inside the e.OptionsPayload method, the destination GridView inside the e.Options.Destination.
    Then you just need to skip adding the item that is already in the collecton.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  9. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 18 Jun 2012 Link to this post

    Hi,

    that's it thank you, but is it not to late? The drop is finished, how do i remoove the existing item?
    Is it the best way to create a modified new List and change the "draggeditems" to my new list in here:

    from
    ReorderingEventArgs reorderingArgs = new ReorderingEventArgs(gridView, draggedItems, gridView.Items.Count);

    to
    ReorderingEventArgs reorderingArgs = new ReorderingEventArgs(gridView, NewItems, gridView.Items.Count);

    Thanks you
    Regards
    Rene
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Jun 2012 Link to this post

    Hello Rene,

     The two events that could be used to control the actions done on drop are OnDropQuery and OnDropInfo. You have access to the destinationGrid and  draggedItems in both of them. Does the OnDropQuery event handler fits your needs better?

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready