0

This is probably a really basic question - but I have a list of items (custom objects) being passed from one winform (.net 3.5) to another. I want to create a local list to store changes that only get persisted if the user clicks save. Currently if the user clicks cancel - the changes are still applied in the first form because I assume the objects are reference type.

I have the save working as it calls a service layer to do the save and then refreshes the other form - but not the cancel.

How do I create a new list from the first list where the objects act independently to the other list? (Hopefully this makes sense :))

Otherwise on cancel I'm going to have to rollback the changes which seems a less efficient way of handling the issue.

Thanks!

Jen
  • 1,964
  • 9
  • 33
  • 59
  • Creating a deep copy of the list isn't exactly an efficient way either. Do consider applying the changes only after a 'save' confirmation. A delegate can do wonders. – Hans Passant Oct 26 '11 at 11:34
  • The list that I'm working with is only a subset of "selected data" and the screen behaviour is such that they wouldn't be likely to perform this action on a large bulk number of items. But thanks for the thought. – Jen Oct 27 '11 at 05:09

1 Answers1

4

You would then have to clone all the entities in the list and add them to a new list. Take a look at this post which has some info on cloning.

Community
  • 1
  • 1
Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103
  • Thanks so much - ended up adding a copy function to my entity which achieved what I needed to :) – Jen Oct 27 '11 at 05:06