Last Updated: 11 Apr 2016 06:59 by ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 18 Mar 2016 07:17
Category: GridView
Type: Bug Report
FIX. RadGridView - NullReferenceException when reordering columns
I've attached a sample project.  Here are the steps to repeat this issue:
1. Run the application
2. Click column A and drag it to the right to reorder it, scrolling the window as it goes
3. You are eventually presented with a NullReferenceException
You may have to try this several times with different columns before the problem manifests.  I have found that moving just beyond the right edge of the main form and moving the mouse cursor up and down a little helps.  I appears this problem only occurs in grids with many columns, so that fast scrolling can occur for multiple seconds when reordering columns.


Sub New()

    Me.RadGridView1.GridViewElement.RegisterService(New MyRadGridViewDragDropService(Me.RadGridView1.GridViewElement))

End Sub

Public Class MyRadGridViewDragDropService
Inherits RadGridViewDragDropService
    Public Sub New(gridViewElement As RadGridViewElement)

    End Sub

    Public Overrides ReadOnly Property Name As String
            Return "RadGridViewDragDropService"
        End Get
    End Property
    Protected Overrides Sub PrepareDragHint(dropTarget As Telerik.WinControls.ISupportDrop)
        Dim dragDropBehavior As IGridDragDropBehavior = Me.GetDragDropBehavior()
        If dragDropBehavior Is Nothing OrElse dragDropBehavior.DragHint Is Nothing _
            OrElse dragDropBehavior.DragHint.Image Is Nothing Then
        End If

        Dim dropTargetItem As RadItem = TryCast(dropTarget, RadItem) 
        If dropTargetItem IsNot Nothing AndAlso dropTargetItem.ElementTree IsNot Nothing _
            AndAlso Not dropTargetItem.ElementTree.Control.Equals(Me.GridViewElement.ElementTree.Control) Then
        End If
        dragDropBehavior.UpdateDropContext(TryCast(Me.Context, ISupportDrag), dropTarget, Me.beginPoint)
        Dim hintSize As Size = dragDropBehavior.GetDragHintSize(dropTarget)
        Dim image As New Bitmap(hintSize.Width, hintSize.Height)
        Dim temp As Graphics = Graphics.FromImage(image)
        dragDropBehavior.DragHint.Paint(temp, New RectangleF(PointF.Empty, hintSize))

        Dim dragHintWindow As New RadLayeredWindow()
        GetType(RadGridViewDragDropService).GetField("dragHintWindow", _
         Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance).SetValue(Me, dragHintWindow)
        dragHintWindow.BackgroundImage = image
    End Sub
End Class