What is the best way to copy a BindingList?
Just use ForEach()? Or are there better ways?
What is the best way to copy a BindingList?
Just use ForEach()? Or are there better ways?
Foreach pretty much is the easiest way, and the performance overhead is minimal if any.
Serialize the object then de-serialize to get a deep cloned non referenced copy
Just pass the old binding list as a parameter for the new binding list, on the constructor.
BindingList has a constructor which can take an IList. And BindingList implements IList. So you can just do the following:
BindingList newBL = new BindingList(oldBL);
Of course that creates a second list that just points at the same objects. If you actually want to clone the objects in the list then you have to do more work.