I have a form where users can modify a collection of objects using a DataGrid. When the form is opened I create a deep copy of the original collection and if the Cancel button is pressed I just discard that copy.
The problem is that when the OK button is pressed I have to reconcile the changes which might be:
- Modified properties of existing objects
- New objects added to any place in the collection.
- Existing objects removed.
- Existing objects re-ordered.
Since I need to keep the original references I can't just clear the collection and add the modified items.
Do you know a simple algorithm that would synchronize two collections like this?
I'm using C# 3.5 so LINQ is available.