This is a migrated thread and some comments may be shown as answers.

BindingList slow performance with large data

1 Answer 1018 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 21 Jul 2016, 09:37 PM

Hello,

This is a not an issue with RadGridView per say, but somewhat related.  Hopefully someone can suggest an alternative solutions for me.

I have a simple RadGridView which is binded to a BindingList with about 2,500 items.  The item that is in BindingList inherits ObservableObject from MVVMLight, hence implements INotifyPropertyChanged interface.  One of my properties is boolean called "Selected" which is binded to a checkbox column.  I have a button "Select All". On click, I need to mark all items as selected.  On the backend, I do a simple foreach loop and set Selected = True.  Here is the code.

foreach (var p in Products)
   p.Selected = true;

Very simple. But this loop takes almost 10 minutes.  I figured out that the issue is related to the BindingList.  I did some isolated Tests (without UI).  Simply created a model that implements INotifyPropertyChanged interface, created 1000, 2000, and 3000 records and evaluated the performance.  The result came out to be the longer the list, the more time per item it takes to set simply selected=true.  Here are results

1000 items => 11 sec total => 0.011 sec/cycle

2000 items => 44 sec total => 0.022 sec/cycle

3000 items => 100 sec total => 0.033 sec/cycle

as you can see the average per cycle increases when there are more items in the BindingList

I did some research and this article explains why this is happening: http://www.blog.dapfor.com/why-bindinglist-is-slow-with-objects-implementing-inotifypropertychanged-interface

I tried using approach from the article above.  My loop works in milliseconds.  Great! But now, my checkbox column in the grid does not get updated until I select each row and loose focus.  Obviously the grid does not get a notification to update its cells.

I also tried setting RaiseListChangedEvents = false before the loop and then  list.RaiseListChangedEvents = true after the loop.  Result is the same.

So my question is

1. Is there an alternative class that implements IBindingList interface which would yield a linear increase in time as more items are added, not exponential?

2. If there is no other way, then I guess my only option is to refresh the grid after I update the binding list.  How do I do this?

3. Any other suggestions?

Thank you in advance.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 22 Jul 2016, 11:01 AM
Hello Michael,

Thank you for writing.

You can optimize this by postponing the grid layout while updating the list. To do that you can use a Begin/End update block. You should postpone the list events as well:
private void radButton1_Click(object sender, EventArgs e)
{
    Stopwatch sw = new Stopwatch();
    sw.Start();
 
    radGridView1.BeginUpdate();
    data.RaiseListChangedEvents = false;
 
    foreach (var item in data)
    {
        item.Checked = !item.Checked;
    }
 
    data.RaiseListChangedEvents = true;
 
    radGridView1.EndUpdate();
    sw.Stop();
    Console.WriteLine(sw.Elapsed);
}

Let me know how this works on your side.

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or