Completed
Last Updated: 14 Mar 2016 07:44 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 29 Feb 2016 12:14
Category: GridView
Type: Bug Report
1
FIX. RadGridView - NullReferenceException on a Windows 10 machine when reordering columns and the TableElement.RowDragHint property is set to null
To reproduce: 

public Form1()
{
    InitializeComponent();

    for (int i = 0; i < 10; i++)
    {
        this.radGridView1.Columns.Add("Col"+i);
    }
    this.radGridView1.TableElement.RowDragHint = null;
}

Workaround:
public Form1()
{
    InitializeComponent();

    for (int i = 0; i < 10; i++)
    {
        this.radGridView1.Columns.Add("Col"+i);
    }
    this.radGridView1.TableElement.RowDragHint = null;

    CustomRadGridViewDragDropService service = new CustomRadGridViewDragDropService(this.radGridView1.GridViewElement);
    this.radGridView1.GridViewElement.RegisterService(service);
    
}
public class CustomRadGridViewDragDropService : RadGridViewDragDropService
{
    public CustomRadGridViewDragDropService(RadGridViewElement gridViewElement) : base(gridViewElement)
    {
    }
    public override string Name
    {
        get
        {
            return typeof(RadGridViewDragDropService).Name;
        }
    }

    protected override void PrepareDragHint(ISupportDrop dropTarget)
    {
        if (this.GridViewElement.TableElement.RowDragHint == null)
        {
            return;
        }
        base.PrepareDragHint(dropTarget);
    }
    protected override IGridDragDropBehavior GetDragDropBehavior()
    {
        IGridDragDropBehavior behavior = null;
        ISupportDrop dropTarget = this.DropTarget;
        if (dropTarget is GridHeaderCellElement)
        {
            behavior = new CustomGridColumnDragDropBehvavior();
            return behavior;
        }
        return base.GetDragDropBehavior();
    }
}

public class CustomGridColumnDragDropBehvavior : GridColumnDragDropBehvavior
{
    public override Size GetDragHintSize(ISupportDrop dropTarget)
    {
        if (this.DragHint==null)
        {
            return new Size(0, 0);
        }
        return base.GetDragHintSize(dropTarget);
    }
}
Attached Files:
0 comments