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
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.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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?
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.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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
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
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.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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
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?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>