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

Getting row dragged/dropped in RadGridView

1 Answer 41 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
acola
Top achievements
Rank 1
acola asked on 05 Oct 2011, 05:16 PM
I'm using the eval version of Silverlight 2011 Q2. I am trying to drag data between 2 RadGridViews, and programmatically access the row that was dragged. I'm having trouble finding much sample code for the DragDropManager - what code I do have, I got from http://www.telerik.com/community/forums/silverlight/drag-and-drop/dragdropmanager-sample-code.aspx However, this seems to only be able to get access to the RadGridView itself, which isn't very helpful. How do I go about getting the row that was dragged?

Here is my code, just slightly modified from the code sample from the above thread. I can get it to send me the entire ItemSource of the gridview, but that doesn't really help.
private void OnDragInitialize(object sender, DragInitializeEventArgs args)
       {
           args.AllowedEffects = DragDropEffects.All;
            //how do I set the data to be the selected row?
           args.Data = ((RadGridView)args.Source).ItemsSource;
           args.DragVisual = new ContentControl { Content = args.Data, ContentTemplate LayoutRoot.Resources["ApplicationTemplate"] as DataTemplate };
       }
 
private void grdTripPrisoners_Drop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
       {
         //this gives me the list of items from the gridview I dragged from
         object whatIGot = e.Data;
       }

I think I could create a method that tracks whenever the selected item in the grid view changes, store the selected item, and then send that along as the args.Data, but it seems like there should be a better way.

Thanks!

1 Answer, 1 is accepted

Sort by
0
acola
Top achievements
Rank 1
answered on 05 Oct 2011, 06:08 PM
Whoops - I just noticed that I can just use the SelectedItem property on the RadGridView to pass the selected row as the arg data. Problem solved!
Tags
DragAndDrop
Asked by
acola
Top achievements
Rank 1
Answers by
acola
Top achievements
Rank 1
Share this question
or