tags:

views:

114

answers:

4

What is the best way to copy a BindingList?

Just use ForEach()? Or are there better ways?

A: 

Foreach pretty much is the easiest way, and the performance overhead is minimal if any.

TomTom
And what about this? BindingList list2 = new BindingList(list1.toList())
Martijn
If you decompile toList you will see it does pretty much the same ;)
TomTom
A: 

Serialize the object then de-serialize to get a deep cloned non referenced copy

Ismail
Agreed. This answer is ridiculous.
TomTom
@tomtom, no it isn't. Depends on the question.
Henk Holterman
+3  A: 

Just pass the old binding list as a parameter for the new binding list, on the constructor.

leppie
A: 

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.

jkohlhepp