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

OnDropQuery not firing

5 Answers 131 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Dom
Top achievements
Rank 1
Dom asked on 10 Jun 2011, 09:51 PM
Hello,

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?

5 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 11 Jun 2011, 09:12 AM
Hi Domingos,

Base on the code posted I have prepared simple applicaton that seems to work correctly. Plase, check the attachement and let us know if this helps resolving your issue. If not, would it be possible to share some additional details about the specific scenario (usage of child windows, popups, etc.)

All the best,
Tsvyatko
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Dom
Top achievements
Rank 1
answered on 13 Jun 2011, 02:48 PM
Hi,
thanks for your quick reply.

I tried your application (in your application it works), form what i saw the difference was you using
TreeListViewDragCue while i was using TreeViewDragCue, and one or two other minor things.

Anyway I changed that and it still doesn't work.
So since you mentionned childwindows, yes I'm using that. I have the main page with RadMenu, if you click on one of the RadMenuItems, this page pop-up using the childwindow from silverlight. in this window i have the 2 grids that I'm trying to drag from one to the other (Well i want to do some other stuff but for now would like to get that working before going into more complicated stuff).

Would the problem come from me using this in a childwindow? Again with the changes from your code I'm not using AutogeneratedColumns and I'm in a childwindow. Again the drag works, but when i got over the datagrid, the icon doesn't change to possible and it doesn't fire up OnDropInfo at any point.
0
Dom
Top achievements
Rank 1
answered on 13 Jun 2011, 03:07 PM
I just tried your application but i put a button only in your mainpage, and i copied all of the code that was in it to a childwindow. In the buttonclick event of the button, the childwindow pops-up and the drag works but can never drop. So drag and drop doesn't work with childwindows? Any workaround?
0
Dom
Top achievements
Rank 1
answered on 13 Jun 2011, 04:37 PM
Found a solution,

added this :

 

if (!e.Options.ParticipatingVisualRoots.Contains(this))
            {
                e.Options.ParticipatingVisualRoots.Add(this);
            }
 in the OnDragQuery method.

Not sure if its the best way or not
0
vishal
Top achievements
Rank 1
answered on 05 Jul 2011, 10:24 PM
Thanks, this worked.
Tags
DragAndDrop
Asked by
Dom
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Dom
Top achievements
Rank 1
vishal
Top achievements
Rank 1
Share this question
or