This question is locked. New answers and comments are not allowed.
Hello,
I've been trying to drag and drop from one gridview to another, the drag part works fine but it never changes to
I use ObservableCollections and i set AllowDrag and Drop in codebehing and in the 2 grids.
So whenever i drag something, i can never drop it. Am I missing something?
I've been trying to drag and drop from one gridview to another, the drag part works fine but it never changes to
DropPossible and doesn't seem to firing the OnDropQuery or OnDropInfo events.
public DragDrop() { InitializeComponent(); LoadData(); RadDragAndDropManager.AddDropQueryHandler(this, OnDropQuery); RadDragAndDropManager.AddDropInfoHandler(this, OnDropInfo); RadDragAndDropManager.AddDragQueryHandler(this, OnDragQuery); RadDragAndDropManager.AddDragInfoHandler(this, OnDragInfo); RadDragAndDropManager.SetAllowDrag(this, true); RadDragAndDropManager.SetAllowDrop(this, true); } private void LoadData() { ObservableCollection<Production> lst = new ObservableCollection<Production>(); ... } void OnDragInfo(object sender, DragDropEventArgs e) { GridViewRow gridViewRow = e.Options.Source as GridViewRow; if (e.Options.Status == DragStatus.DragInProgress) { //Set up a drag cue: TreeViewDragCue cue = new TreeViewDragCue(); //Here we need to choose a template for the items: //cue.ItemTemplate = this.Resources["ProductTemplate"] as DataTemplate; cue.ItemsSource = new List<object>() { e.Options.Payload }; e.Options.DragCue = cue; } else if (e.Options.Status == DragStatus.DragComplete) { //IList source = gridView.ItemsSource as IList; //foreach (object draggedItem in draggedItems) //{ // source.Remove(draggedItem); // } } } protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e) { if (e.Options.Status == DragStatus.DragQuery) { // The issue that is being dragged: GridViewRow gridViewRow = e.Options.Source as GridViewRow; if (gridViewRow != null) { e.Options.Payload = gridViewRow.Item; e.QueryResult = true; e.Handled = true; } else { e.QueryResult = null; } } else { // The "else" handles the DropSource query status. e.QueryResult = true; } } private void OnDropInfo(object sender, DragDropEventArgs e) { TreeViewDragCue cue = e.Options.DragCue as TreeViewDragCue; var issue = e.Options.Payload as LotExpedition; if (e.Options.Status == DragStatus.DropPossible) { // Set a suitable text: cue.DragActionContent = "Change the status of the item."; cue.IsDropPossible = true; //order.Background = this.Resources["DropPossibleBackground"] as Brush; } else if (e.Options.Status == DragStatus.DropImpossible) { cue.DragActionContent = null; cue.IsDropPossible = false; } else if (e.Options.Status == DragStatus.DropComplete) { //IList items = order.ItemsSource as IList; MessageBox.Show("TODO: Change the status of the issue here."); } } void OnDropQuery(object sender, DragDropQueryEventArgs e) { // We allow drop only if the dragged items are products: ICollection draggedItems = e.Options.Payload as ICollection; var gridView = e.Options.Destination as RadGridView; var draggedItem = e.Options.Payload as LotExpedition; // Allow drop: e.QueryResult = true; }I use ObservableCollections and i set AllowDrag and Drop in codebehing and in the 2 grids.
<telerik:RadGridView x:Name="GridView2" Grid.Row="3" telerikDragDrop:RadDragAndDropManager.AllowDrop="True" RowStyle="{StaticResource rowStyle}" ShowGroupPanel="False" AutoGenerateColumns="False" IsReadOnly="True"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Produit" DataMemberBinding="{Binding Produit }" MaxWidth="100"/> <telerik:GridViewDataColumn Header="Transfert Type" DataMemberBinding="{Binding transferType }" MaxWidth="100"/> <Grid.Resources> <Style x:Key="rowStyle" TargetType="telerik:GridViewRow"> <Setter Property="dragDrop:RadDragAndDropManager.AllowDrag" Value="True" /> </Style> </Grid.Resources> <telerik:GridViewDataColumn Header="transferDetail" DataMemberBinding="{Binding transferDetail }" MaxWidth="100"/> <telerik:GridViewDataColumn Header="Unit" DataMemberBinding="{Binding unit}" MaxWidth="150"/> <telerik:GridViewDataColumn Header="Secteur usine" DataMemberBinding="{Binding SecteurUsine }" MaxWidth="50"/> <telerik:GridViewDataColumn Header="container " DataMemberBinding="{Binding container}" MaxWidth="100"/> <telerik:GridViewDataColumn Header="Cost" DataMemberBinding="{Binding cost}" MaxWidth="100"/> </telerik:RadGridView.Columns> </telerik:RadGridView> <telerik:RadGridView x:Name="GridView4" Grid.Row="6" telerikDragDrop:RadDragAndDropManager.AllowDrop="True" ShowGroupPanel="False" AutoGenerateColumns="False" IsReadOnly="True"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Produit" DataMemberBinding="{Binding Produit }" MaxWidth="100"/> <telerik:GridViewDataColumn Header="Transfert Type" DataMemberBinding="{Binding transferType }" MaxWidth="100"/> <telerik:GridViewDataColumn Header="transferDetail" DataMemberBinding="{Binding transferDetail }" MaxWidth="100"/> <telerik:GridViewDataColumn Header="Unit" DataMemberBinding="{Binding unit}" MaxWidth="150"/> <telerik:GridViewDataColumn Header="Secteur usine" DataMemberBinding="{Binding SecteurUsine }" MaxWidth="50"/> <telerik:GridViewDataColumn Header="container " DataMemberBinding="{Binding container}" MaxWidth="100"/> <telerik:GridViewDataColumn Header="Cost" DataMemberBinding="{Binding cost}" MaxWidth="100"/> </telerik:RadGridView.Columns> </telerik:RadGridView>So whenever i drag something, i can never drop it. Am I missing something?