Completed
Last Updated: 08 Aug 2022 10:24 by ADMIN
Release R3 2022 (LIB 2022.2.808)
Patrick
Created on: 15 Jul 2022 08:45
Category: ListView
Type: Bug Report
0
RadListView: System.NullReferenceException while dragging an item in bound mode

Use the attached project and start dragging an item to trigger scrolling. As a result, an error occurs. The attached gif file illustrates the steps.

Workaround: 

Me.RadListView1.ListViewElement.DragDropService = New CustomListViewDragDropService(Me.RadListView1.ListViewElement)

    Public Class CustomListViewDragDropService
        Inherits ListViewDragDropService

        Public Sub New(owner As RadListViewElement)
            MyBase.New(owner)
        End Sub
        Protected Overrides Sub OnPreviewDragOver(e As RadDragOverEventArgs)
            MyBase.OnPreviewDragOver(e)
        End Sub
        Protected Overrides Sub HandleMouseMove(mousePos As Point)
            If Not Me.Initialized Then
                MyBase.HandleMouseMove(mousePos)
            End If

            Dim mi As MethodInfo = GetType(RadDragDropService).GetMethod("DoDrag", BindingFlags.Instance Or BindingFlags.NonPublic)
            mi.Invoke(Me, New Object() {mousePos})

            Dim fi2 As FieldInfo = GetType(RadDragDropService).GetField("beginPoint", BindingFlags.Instance Or BindingFlags.NonPublic)
            fi2.SetValue(Me, mousePos)

            Dim fi As FieldInfo = GetType(ListViewDragDropService).GetField("dragHintWindow", BindingFlags.Instance Or BindingFlags.NonPublic)

            Dim dragHintWindow = fi.GetValue(Me)

            If dragHintWindow Is Nothing AndAlso Me.CanCommit Then
                Me.PrepareDragHint()
            End If

            Me.UpdateDragHintLocation(mousePos)
            Dim viewElement As RadListViewElement = Me.Owner
            Dim item As BaseListViewVisualItem = TryCast(Me.DropTarget, BaseListViewVisualItem)

            If item IsNot Nothing AndAlso item.Data IsNot Nothing AndAlso Not item.Data.Owner.Equals(viewElement) Then
                viewElement = item.Data.Owner
            End If

            Dim clientPos As Point = viewElement.PointFromScreen(mousePos)

            If (clientPos.Y < 0 AndAlso viewElement.ViewElement.Orientation = Orientation.Vertical) OrElse (clientPos.X < 0 AndAlso viewElement.ViewElement.Orientation = Orientation.Horizontal) Then
                viewElement.ViewElement.Scroller.Scrollbar.PerformSmallDecrement(1)
            ElseIf (clientPos.Y > viewElement.Size.Height AndAlso viewElement.ViewElement.Orientation = Orientation.Vertical) OrElse (clientPos.X > viewElement.Size.Width AndAlso viewElement.ViewElement.Orientation = Orientation.Horizontal) Then
                viewElement.ViewElement.Scroller.Scrollbar.PerformSmallIncrement(1)
            End If
        End Sub
    End Class

0 comments