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

DropHandler Drag & Drop fro Grid to Grid

8 Answers 112 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
ITA
Top achievements
Rank 1
ITA asked on 13 Jun 2012, 11:56 AM
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

8 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 13 Jun 2012, 12:26 PM
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 >>

0
ITA
Top achievements
Rank 1
answered on 13 Jun 2012, 01:04 PM
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?

0
Dimitrina
Telerik team
answered on 14 Jun 2012, 01:16 PM
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 >>

0
ITA
Top achievements
Rank 1
answered on 15 Jun 2012, 07:39 AM
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
0
ITA
Top achievements
Rank 1
answered on 15 Jun 2012, 11:14 AM
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
0
Dimitrina
Telerik team
answered on 15 Jun 2012, 11:33 AM
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 >>

0
ITA
Top achievements
Rank 1
answered on 18 Jun 2012, 06:57 AM
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
0
Dimitrina
Telerik team
answered on 18 Jun 2012, 09:43 AM
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 >>

Tags
DragAndDrop
Asked by
ITA
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
ITA
Top achievements
Rank 1
Share this question
or