Okay, let's imagine we've a model object that looks like this... public Class Customer { private string _Name; public string Name { get { return _Name; } set { _Name = value; } } private string _Address; public string Address { get { return _Address; } set { _Address = value; } } } Let's also imagine that we've got it bound to a view as a datasource of a binding source, so now when we change a value in a control and tab out of it, that change is flushed down to the model object. Woot, and we had to do no work! Fantastic! But not so fast, there is a slight problem though. Now let's imagine that we have a BindingList of these objects bound to a list in a view representing the results of a search. Now, select one of the items, right click and select "Edit" and up pops the CustomerView in "Edit" mode. Change a value, tab out of it and now close the view without saving it. Open the item in "Edit" mode again and you can see that your changes have been persisted in the object, grrrrr! That's because the binding source flushes the changes as soon as you tab out. So, what's the solution. Well, you could impliment IEditableObject, but at the end of the day you still have to handle the actions on throwing away the changes - using something like the momento pattern for example, but all that seems a little long winded and complicated to me. My, simplistic, solution to this - especially if the data is volitile - is simply to re-read the data from the database. I just write a "refresh" method on the object, and if the user selects to throw away the changes, I call the refresh method, which makes a round trip to the database and updates all the object's properties. Job done!
(Technorati tags: , )