Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't BindingList(Of T) have AddRange Member?

I think the title pretty much captures my question, but a little bit of background follows:

When a form I have loads it adds a couple of thousand (30k odd) objects to a binding list. When my application loads the first time it takes multiple seconds (around 10 or so from memory) for it to loop through the list of objects and add it to the BindingSource using the add function. However, when this happens on subsequent forms with the same code for loading it only takes a second or two.

So my queries would be:
1. Why doesn't BindingList(Of T) have AddRange Member?
2. Would the initial and subsequent adds be quicker with an AddRange function?
3. Any ideas why one version of the code runs slower than identical versions?

Thanks for any help you might be able to provide.

like image 862
ChrisAU Avatar asked Sep 22 '10 06:09

ChrisAU


1 Answers

I am not sure why no AddRange method is available. You can easily write your own as an extension method:

    /// <summary>
    /// Adds all the data to a binding list
    /// </summary>
    public static void AddRange<T>(this BindingList<T> list, IEnumerable<T> data)
    {
        if (list == null || data == null)
        {
            return;
        }

        foreach (T t in data)
        {
            list.Add(t);
        }
    }
like image 120
Paul Richards Avatar answered Oct 03 '22 21:10

Paul Richards