Completed
Last Updated: 09 Jul 2021 11:20 by ADMIN
Release R3 2021
Stoyan
Created on: 23 Jun 2021 15:07
Category: ListView
Type: Bug Report
1
RadListView: Unhandled exception on Items.Remove

System.NullReferenceException: 'Object reference not set to an instance of an object.' when removing items from the list:

 public Form1()
 {
     InitializeComponent();
     for (var i = 0; i < 30; i++)
     {
         var item = new ListViewDataItem();
         radListView2.Items.Insert(0, item);
         item[0] = i;
         item[1] = i;
         item[2] = i;
         item[3] = i;
     }
 }
private void radButton1_Click(object sender, EventArgs e)
{
    try
    {
        radListView2.BeginUpdate();

        foreach (var lvi in radListView2.Items.ToArray())
        {
            radListView2.Items.Remove(lvi);
           
        }
    }
    finally
    {
        radListView2.EndUpdate();
    }
}

3 comments
ADMIN
Nadya | Tech Support Engineer
Posted on: 28 Jun 2021 15:19

Hello, Stoyan,

I would like to follow up on this. Our developers are working on this issue and when the testing process is complete we would be able to introduce a fix in our upcoming LIB scheduled for next week. Make sure that you follow the feedback item in order to get notified when its status has changed. Thus, you should be able to download it from your Telerik account and test locally how it works with the fix. 

I hope this information is useful. Please let me know if you have other questions.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Stoyan
Posted on: 24 Jun 2021 06:58

Unfortunately, the workaround does not bring the necessary performance gain.

13 sec is a lot. Same code on standard ListView takes only 4 sec and only 0.13 sec with BeginUpdate() / EndUpdate().

radListView2.Items.Clear() is not an option, as in real case i have to remove only certain Items (most of them).

ADMIN
Nadya | Tech Support Engineer
Posted on: 23 Jun 2021 15:19

Hi, Stoyan,

To workaround use the SuspendLayout/ResumeLayout code block:

private void radButton1_Click(object sender, EventArgs e)
{
    try
    {
        radListView2.SuspendLayout();

        foreach (var lvi in radListView2.Items.ToArray())
        {
            radListView2.Items.Remove(lvi);
           
        }
    }
    finally
    {
        radListView2.ResumeLayout();
    }
}

 

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.