RadGridView drag item template

2 posts, 0 answers
  1. Adam
    Adam  avatar
    30 posts
    Member since:
    Jun 2009

    Posted 04 Nov 2009 Link to this post

    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.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;

  2. Miroslav
    Miroslav avatar
    922 posts

    Posted 10 Nov 2009 Link to this post

    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:


    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,
    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.
Back to Top