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.
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With