Getting row dragged/dropped in RadGridView

2 posts, 0 answers
  1. acola
    acola avatar
    15 posts
    Member since:
    Aug 2006

    Posted 05 Oct 2011 Link to this post

    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!
  2. acola
    acola avatar
    15 posts
    Member since:
    Aug 2006

    Posted 05 Oct 2011 Link to this post

    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!
  3. DevCraft banner
Back to Top