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

payload null when dragging a focussed item from radgridview

1 Answer 65 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Sjors
Top achievements
Rank 1
Sjors asked on 25 May 2012, 12:38 PM
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?

1 Answer, 1 is accepted

Sort by
0
Sjors
Top achievements
Rank 1
answered on 29 Jun 2012, 06:56 AM
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;
        }
Tags
DragAndDrop
Asked by
Sjors
Top achievements
Rank 1
Answers by
Sjors
Top achievements
Rank 1
Share this question
or