Declined
Last Updated: 06 Oct 2021 08:23 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 03 Apr 2017 09:52
Category: GridView
Type: Bug Report
1
FIX. RadGridView - scrolling stops working to the top/bottom row when the AllowAutoScrollRowsWhileDragging property is set to true and a custom RadDragDropService is used
To reproduce: please open the attached sample project and follow the steps illustrated in the attached gif file.

Workaround: 
1. You still can scroll while dragging a row by using the mouse wheel.

2. Use the grid in unbound mode and set the AllowRowReorder property to true instead of using a custom RadDragDropService.

3. Use a custom drag and drop service:

public class CustomDragDropService : RadGridViewDragDropService
{
    public CustomDragDropService(RadGridViewElement gridViewElement) : base(gridViewElement)
    {
    }

    public override string Name
    {
        get
        {
            return typeof(RadGridViewDragDropService).Name;
        }
    }

    protected override void HandleMouseMove(System.Drawing.Point mousePosition)
    {
        base.HandleMouseMove(mousePosition);
        System.Drawing.Point location = this.GridViewElement.ElementTree.Control.PointToClient(Control.MousePosition);
        GridTableElement tableElement = this.GetTableElementAtPoint(location);

        ISupportDrag supportDrag = this.Context as ISupportDrag;
        object dataContext = supportDrag.GetDataContext();

        if (this.AllowAutoScrollRowsWhileDragging && dataContext == null)
        {
            ScrollRows(tableElement, location);
        }
    }

    private void ScrollRows(GridTableElement tableElement, System.Drawing.Point location)
    {
        ScrollableRowsContainerElement scrollableRows = tableElement.ViewElement.ScrollableRows;
        RadScrollBarElement vScrollbar = GetVeritcalScrollbar(tableElement);
        System.Drawing.Rectangle containerBounds = scrollableRows.ControlBoundingRectangle;

        if (containerBounds.Contains(location) ||
            location.X < containerBounds.X ||
            location.X > containerBounds.Right)
        {
            return;
        }

        int delta = 0;

        if (location.Y > containerBounds.Bottom)
        {
            delta = location.Y - containerBounds.Bottom;
        }
        else if (location.Y < containerBounds.Y)
        {
            delta = location.Y - containerBounds.Y;
        }

        if (delta != 0 && vScrollbar.Visibility == ElementVisibility.Visible)
        {
            vScrollbar.Value = ClampValue(vScrollbar.Value + delta,
                vScrollbar.Minimum,
                vScrollbar.Maximum - vScrollbar.LargeChange + 1);
        }
    }

    private int ClampValue(int value, int minimum, int maximum)
    {
        if (value < minimum)
        {
            return minimum;
        }
        if (maximum > 0 && value > maximum)
        {
            return maximum;
        }
        return value;
    }

    private RadScrollBarElement GetVeritcalScrollbar(GridTableElement tableElement)
    {
        if (GridViewElement.UseScrollbarsInHierarchy)
        {
            return tableElement.VScrollBar;
        }
        return GridViewElement.TableElement.VScrollBar;
    }
}

public RadForm1()
{
    InitializeComponent();
    CustomDragDropService customService = new CustomDragDropService(radGridView1.GridViewElement);
    radGridView1.GridViewElement.RegisterService(customService);
}
1 comment
ADMIN
Dimitar
Posted on: 04 Oct 2021 04:29

Hello,

The problem lies in the RowSelectionGridBehavior:

public class RowSelectionGridBehavior : GridDataRowBehavior

When using a custom starting of the drag&drop like the following:

RadGridViewDragDropService svc = this.GridViewElement.GetService<RadGridViewDragDropService>();
svc.Start(row);

The row should not be used directly but in a SnapshotDragItem like this:

RadGridViewDragDropService svc = GridViewElement.GetService<RadGridViewDragDropService>();
svc.Start(new SnapshotDragItem(row));

Using the row as context breaks the drag&drop because the drag&drop service uses VisualElements and the RadGridView uses virtualization. The problem lies when the item that we drag leaves the visible area. Then it is disconnected from its RowInfo and another RowInfo is connected to it, which breaks the automatic scrolling and will break the drop operation in the end as well.

The solution is to use "new SnapshotDragItem(row)", which preserves the original rowInfo.

We will update a series of help articles and KBs, which are currently misleading about this specific behavior.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.