Completed
Last Updated: 07 Jul 2020 08:23 by ADMIN
Release R3 2020 (LIB 2020.2.713)
Wojciech
Created on: 01 Jul 2020 13:28
Category: GridView
Type: Bug Report
4
RadGridView: Self referencing hierarchy grid with Excel filters throws NullReferenceException when checkbox filter is turned off and column is sorted

Hello,

We are experiencing a strange behaviour of RadGridView set as a self referencing hierarchy when used with Excel filters.

Once we use predefined filter values (both, build-in and custom defined by us) the filter icon is highlitghted when none of the filter is marked. This higlight can be removed when clear filters button of filter popup is used or FilterDescriptors are cleared. If we do not clear the filters manually, and, for instance, sort grid column the application crashes with internal error of the grid. Error reads Object reference not set to an instance of object.

Attached movie will explain it better. I have also attached a ver simple sample project with data (which does not make sense, just for visualisation) that should fail when you repeat steps described above (turn today or last 7 days filter, apply, select no filter, apply and try to sort the same column).

Is there a workaround or specific conditions we need to apply to have it working?

Thanks for your advice.

I'm also attaching errors details:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of object. /this message comes in Polish, translated
  Source=Telerik.WinControls.GridView
  StackTrace:
   at Telerik.WinControls.UI.GridViewTemplate.PerformHierarchyFilter(GridViewRowInfo rowInfo)
   at Telerik.WinControls.Data.RadCollectionView`1.PassesFilter(TDataItem item)
   at Telerik.Collections.Generic.HybridIndex`1.GetFilteredItems(IEnumerable`1 e)
   at Telerik.Collections.Generic.HybridIndex`1.PerformWithQuickSort()
   at Telerik.Collections.Generic.HybridIndex`1.Perform()
   at Telerik.Collections.Generic.HybridIndex`1.get_Items()
   at Telerik.Collections.Generic.Index`1.get_Count()
   at Telerik.WinControls.Data.GroupBuilder`1.get_Groups()
   at Telerik.WinControls.Data.SnapshotCollectionView`1.get_Groups()
   at Telerik.WinControls.UI.GridViewInfo.LoadHierarchicalData(GridViewHierarchyRowInfo parent, ICollectionView`1 sourceView)
   at Telerik.WinControls.UI.GridViewInfo.Refresh()
   at Telerik.WinControls.UI.GridViewInfo.get_ChildRows()
   at Telerik.WinControls.UI.GridTableElement.UpdateViewCore(Object sender, DataViewChangedEventArgs args)
   at Telerik.WinControls.UI.GridTableElement.UpdateView(Object sender, DataViewChangedEventArgs args)
   at Telerik.WinControls.UI.GridTableElement.ProcessTemplateEvent(GridViewEvent eventData)
   at Telerik.WinControls.UI.GridTableElement.Telerik.WinControls.UI.IGridViewEventListener.ProcessEvent(GridViewEvent eventData)
   at Telerik.WinControls.UI.GridViewEventProcessEntity.ProcessCollection(GridViewEvent gridEvent, PriorityWeakReferenceList list, GridEventProcessMode processMode)
   at Telerik.WinControls.UI.GridViewEventProcessEntity.ProcessEvent(GridViewEvent gridEvent)
   at Telerik.WinControls.UI.GridViewSynchronizationService.NotifyListeners(GridViewEvent gridEvent)
   at Telerik.WinControls.UI.GridViewSynchronizationService.FlushEvents()
   at Telerik.WinControls.UI.GridViewSynchronizationService.DispatchEvent(GridViewEvent gridEvent)
   at Telerik.WinControls.UI.GridViewSynchronizationService.DispatchEvent(GridViewTemplate template, GridViewEvent eventData, Boolean postUI)
   at Telerik.WinControls.UI.GridViewTemplate.DispatchEvent(GridViewEvent gridEvent, Boolean postUI)
   at Telerik.WinControls.UI.GridViewTemplate.DispatchDataViewChangedEvent(Object sender, DataViewChangedEventArgs args)
   at Telerik.WinControls.UI.GridViewTemplate.OnViewChanged(Object sender, DataViewChangedEventArgs e)
   at Telerik.WinControls.UI.MasterGridViewTemplate.OnViewChanged(Object sender, DataViewChangedEventArgs e)
   at Telerik.WinControls.UI.GridViewTemplate.CollectionView_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.Data.RadCollectionView`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.WinControls.Data.RadDataView`1.RebuildData(Boolean notify)
   at Telerik.WinControls.Data.RadDataView`1.RefreshOverride()
   at Telerik.WinControls.Data.RadDataView`1.OnNotifyPropertyChanged(PropertyChangedEventArgs e)
   at Telerik.WinControls.Data.RadCollectionView`1.OnNotifyPropertyChanged(String propertyName)
   at Telerik.WinControls.Data.RadCollectionView`1.sortDescriptors_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Collections.Generic.NotifyCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.WinControls.UI.GridViewSortDescriptorCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Collections.Generic.NotifyCollection`1.InsertItem(Int32 index, T item)
   at Telerik.WinControls.Data.SortDescriptorCollection.InsertItem(Int32 index, SortDescriptor item)
   at Telerik.WinControls.UI.GridViewSortDescriptorCollection.InsertItem(Int32 index, SortDescriptor item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Telerik.WinControls.UI.GridViewColumn.Sort(RadSortOrder sortOrder, Boolean multiSortMode)
   at Telerik.WinControls.UI.GridHeaderCellElement.Sort(RadSortOrder sortOrder)
   at Telerik.WinControls.UI.GridHeaderRowBehavior.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.UI.BaseGridBehavior.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.UI.RadGridView.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at Telerik.WinControls.UI.RadGridView.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
   at bindingListEx_celLike.My.MyApplication.Main(String[] Args) in :line 81

2 comments
Wojciech
Posted on: 03 Jul 2020 19:24

I have succesfully implemented proposed solution into our project.

Thank you.

ADMIN
Nadya | Tech Support Engineer
Posted on: 02 Jul 2020 12:41

Hello, Wojciech,

The provided project and video demonstrating the issue are greatly appreciated.

I confirm there is an issue when unchecking the checkbox while filtering in the self-reference hierarchy grid. I have logged it in our feedback portal by making this thread public. You can track its progress, subscribe for status changes, and add your comments on the following link - feedback item.

I have also updated your Telerik points

Currently, the possible solution that I can suggest is to create a custom RadDateFilterPopup and override the OnButtonOkClick method. Then, replace the base filter pop with the custom one in the FilterPopupRequired event. Please refer to the following code snippet:

Private Sub Rgv_FilterPopupRequired(sender As Object, e As FilterPopupRequiredEventArgs)
    If TypeOf e.FilterPopup Is RadDateFilterPopup Then
        e.FilterPopup = New MyRadDateFilterPopup(e.Column)
    End If
End Sub

Public Class MyRadDateFilterPopup
    Inherits RadDateFilterPopup

    Public Sub New(dataColumn As GridViewDataColumn)
        MyBase.New(dataColumn)
    End Sub

    Protected Overrides Sub OnButtonOkClick(e As EventArgs)
        Dim compositeFilterDescriptor As CompositeFilterDescriptor = New CompositeFilterDescriptor()
        compositeFilterDescriptor.PropertyName = MyBase.DataColumn.Name
        compositeFilterDescriptor.LogicalOperator = FilterLogicalOperator.[Or]

        If Me.CalendarItem.IsChecked Then

            If Me.CalendarItem.CalendarElement.Calendar.SelectedDates.Count = 0 Then
                Dim dt As DateTime = Me.CalendarItem.CalendarElement.Calendar.FocusedDate
                Dim descriptor As DateFilterDescriptor = New DateFilterDescriptor(MyBase.DataColumn.Name, FilterOperator.IsEqualTo, dt, False)
                compositeFilterDescriptor.FilterDescriptors.Add(descriptor)
            Else

                For Each dt As DateTime In Me.CalendarItem.CalendarElement.Calendar.SelectedDates
                    Dim descriptor As DateFilterDescriptor = New DateFilterDescriptor(MyBase.DataColumn.Name, FilterOperator.IsEqualTo, dt, False)
                    compositeFilterDescriptor.FilterDescriptors.Add(descriptor)
                Next
            End If
        End If

        For Each item As RadItem In Me.Items
            Dim filterDateItem As FilterMenuCustomDateItem = TryCast(item, FilterMenuCustomDateItem)

            If filterDateItem IsNot Nothing Then

                If filterDateItem.IsChecked AndAlso Not SearchForAppliedFilterDescriptors(compositeFilterDescriptor, filterDateItem.FilterDescriptor) Then
                    compositeFilterDescriptor.FilterDescriptors.Add(filterDateItem.FilterDescriptor)
                End If
            End If
        Next

If String.IsNullOrEmpty(compositeFilterDescriptor.Expression) Then
    compositeFilterDescriptor = Nothing
End If

        MyBase.FilterDescriptor = compositeFilterDescriptor
        OnFilterConfirmed()

    End Sub

    Private Function SearchForAppliedFilterDescriptors(ByVal descriptor1 As FilterDescriptor, ByVal descriptor2 As FilterDescriptor) As Boolean
        If descriptor1.Expression = descriptor2.Expression Then
            Return True
        End If

        If TypeOf descriptor1 Is CompositeFilterDescriptor Then

            For Each descriptor As FilterDescriptor In (CType(descriptor1, CompositeFilterDescriptor)).FilterDescriptors

                If SearchForAppliedFilterDescriptors(descriptor, descriptor2) Then
                    Return True
                End If
            Next
        End If

        Return False
    End Function
End Class

I attached the updated project to this thread for your reference. The achieved result is demonstrated in the gif file.

I hope this helps. If you have further questions do not hesitate to contact me.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.