BindingList slow performance with large data

2 posts, 0 answers
  1. Michael
    Michael avatar
    41 posts
    Member since:
    Oct 2010

    Posted 21 Jul Link to this post


    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:

    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.

  2. Dimitar
    Dimitar avatar
    1335 posts

    Posted 22 Jul Link to this post

    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();
        data.RaiseListChangedEvents = false;
        foreach (var item in data)
            item.Checked = !item.Checked;
        data.RaiseListChangedEvents = true;

    Let me know how this works on your side.

    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.
  3. DevCraft banner
Back to Top