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

RadGridView drag item template

1 Answer 106 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 04 Nov 2009, 09:35 PM
Hi, I'm trying to drag a radgridview row to a treeview. I had this working with listbox, but now I'm switching out the listbox for radgridview. With the listbox I was using the TreeViewDragCue with the listbox itemtemplate, but I'm not sure how to set the itemtemplate for the cue with the radgridview. I tried creating a DataTemplate class, but the items to not seem to get bound. How can I set the item template in the cue and have it use the row data in the binding to display the cue correctly? This is the code I'm using to set the cue:

  public void RadGridView_OnDragQuery(object sender, DragDropQueryEventArgs e)
        {
            if (e.Options.Status == DragStatus.DragQuery)
            {
                e.QueryResult = true;
                e.Handled = true;

                var payload = RadGridView.SelectedItems.Cast<object>().ToList();
                e.Options.Payload = payload;

                //Here we generate the DragCue. Technically we should generate it in the
                //DragInfo event with Status DragInProgress. This way we keep the
                //presentation and a possible business logic separate. We can do it in the
                //DragQuery event when we are not interested in this separation.
                e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();
                var cue = new TreeViewDragCue();

                //Please note that we cannot set *any* source since the items may be
                //visual objects which cannot be displayed twice. This method tries to
                //find their non-visual believable representations.
                cue.SetSafeItemsSource(payload);
                cue.DataContext = payload[0];
                cue.ItemTemplate = new ElementNodeDragDataTemplate();


                cue.IsDropPossible = false;
                e.Options.DragCue = cue;
            }

            if (e.Options.Status == DragStatus.DropSourceQuery)
            {
                e.QueryResult = true;
                e.Handled = true;
            }

        }

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 10 Nov 2009, 03:18 PM
Hi Adam ,

I am sorry for the delayed answer.

If the DragQuery method is in the context of a UserControl or other control that has a resource dictionary, you can ge the template from the resources of the UserControl like so:

cue.ItemTemplate = this.Resources["ProductTemplate"] as DataTemplate;

This is done in this example:

http://demos.telerik.com/silverlight/#DragAndDrop/TreeToGrid

If you want, you may put this template in the ResourceDictionary of the RadGridView so that the code for this handler will be more generic.

Do you think this will work in your case?

Kind regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
DragAndDrop
Asked by
Adam
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or