Completed
Last Updated: 27 Mar 2023 06:39 by ADMIN
Release R1 2023 SP1
Ark Technologies
Created on: 03 Nov 2022 08:22
Category: GridView
Type: Bug Report
1
RadGridView: NullReferenceException when adding/deleting records and search is applied

Steps to reproduce:

1. Bind the grid and enable the search row

2. Enter some search text

3. Delete records from the applied DataSource collection. It may be necessary to perform the delete operation several times before the error occurs.

The error can be reproduced with the following code snippet: 

    Dim dt As New DataTable
    Sub New()

        InitializeComponent()

        dt.Columns.Add("Id", GetType(Integer))
        dt.Columns.Add("Name", GetType(String))
        For index = 1 To 10000
            dt.Rows.Add(index, Guid.NewGuid.ToString())

        Next
        Me.RadGridView1.DataSource = dt
        Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill

        Me.RadGridView1.AllowSearchRow = True

    End Sub

    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        For index = 1 To 50
            dt.Rows.RemoveAt(0)
        Next
    End Sub

There is a sample project attached as well and its result is illustrated in the gif file.

Stack trace:

   at Telerik.WinControls.UI.MasterGridViewTemplate.set_CurrentRow(GridViewRowInfo value)
   at Telerik.WinControls.UI.RadGridView.set_CurrentRow(GridViewRowInfo value)
   at Telerik.WinControls.UI.GridViewSearchRowInfo.SetCurrent(GridSearchResultCellInfo cell)
   at Telerik.WinControls.UI.GridViewSearchRowInfo.SetCurrent(GridSearchResultCellInfo cell, Boolean checkInvokeRequired)
   at Telerik.WinControls.UI.GridViewSearchRowInfo.SelectNextSearchResult()
   at Telerik.WinControls.UI.GridViewSearchRowInfo.Search(String criteria)
   at Telerik.WinControls.UI.GridViewSearchRowInfo.Telerik.WinControls.UI.IGridViewEventListener.PostProcessEvent(GridViewEvent eventData)
   at Telerik.WinControls.UI.GridViewEventProcessEntity.ProcessCollection(GridViewEvent gridEvent, PriorityWeakReferenceList list, GridEventProcessMode processMode)
   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.GridViewRowCollection.DispatchDataViewChangedEvent(DataViewChangedEventArgs args, GridEventType type)
   at Telerik.WinControls.UI.GridViewRowCollection.ListSource_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.Data.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.Data.RadListSource`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.WinControls.Data.RadListSource`1.RemoveItem(Int32 index)
   at Telerik.WinControls.Data.RadListSource`1.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
   at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
   at System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.BindingSource.InnerList_ListChanged(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType type, Int32 index)
   at System.ComponentModel.BindingList`1.RemoveItem(Int32 index)
   at System.Collections.ObjectModel.Collection`1.Remove(T item)
   at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Remove(Object value)
   at System.Windows.Forms.BindingSource.Remove(Object value)

 

1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 03 Nov 2022 08:28

Hello,

Thank you for bringing this to our attention.

Currently, due to the internal implementation of the async search functionality, the possible solution is to use RadGridView's BeginUpdate/EndUpdate block while deleting records:

    Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
        Me.RadGridView1.BeginUpdate()
        For index = 1 To 50
            dt.Rows.RemoveAt(0)
        Next
        Me.RadGridView1.EndUpdate()
    End Sub

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.