payload null when dragging a focussed item from radgridview

2 posts, 0 answers
  1. Sjors
    Sjors avatar
    9 posts
    Member since:
    May 2012

    Posted 25 May 2012 Link to this post

    Hi, I have some strange behaviour

    I have 2 radgridviews and drag/dropping works ok.
    Except for one situation

    When I have a radgridview that gets it's databound collection reset,
    Sometimes an row from in the gridview has focus but is not selected after the update (a rectangle in the cell, but no color).
    This behaviour (setting the focus) is weird (because i don't know what causes it), but not problematic.

    However draganddropmanager seems to be affected by this focus.
    If I drag the focussed item from one grid to another, the DragDropEventArgs.Options.Payload is empty (count=0).
    when I select another row, and come back to my original focussed row and select it, the payload get's filled.

    So when a row has focus just after the radgridview collection has been refreshed, when the item is being dragged the payload is empty.

    Is this a known issue?

  2. Sjors
    Sjors avatar
    9 posts
    Member since:
    May 2012

    Posted 29 Jun 2012 Link to this post

    i fixed this problem with the following code

    protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)
            {
                var sourceGridView = sender as RadGridView;
                var gridViewRow = e.Options.Source as GridViewRow;


                if (sourceGridView == null || gridViewRow == null)
                {
                    return;
                }


                if (e.Options.Status == DragStatus.DragQuery)
                {
                    if (AllowedDragSourceConfigurations.Any(o => o.Control.Name.Equals(sourceGridView.Name)))
                    {
                        e.Options.DragCue = DragAndDropHelper.SetTreeViewDragCue(e.Options.DragCue, new SolidColorBrush(Colors.Green), true);
                    }
                    else
                    {
                        e.Options.DragCue = DragAndDropHelper.SetTreeViewDragCue(e.Options.DragCue, new SolidColorBrush(Colors.Red), false);
                    }
                }


                e.QueryResult = InitiateDrag(sourceGridView, e);
                e.Handled = true;
            }


            protected virtual bool InitiateDrag(RadGridView gridView, DragDropQueryEventArgs dragDropArgs)
            {
                var payload =  gridView.SelectedItems.ToList();


                //Telerik_bug: dragging from a cell with focus (black rectangle) on a non-selected row will have no selected items
                if (payload.Count==0)
                {
                    if (gridView.CurrentCell != null && gridView.CurrentCell.ParentRow != null && gridView.CurrentCell.ParentRow.DataContext != null)
                    {
                        payload.Add(gridView.CurrentCell.ParentRow.DataContext);
                    }
                }
                dragDropArgs.Options.Payload = payload;
                return true;
            }
  3. DevCraft banner
Back to Top