views:

17

answers:

1

When using the PropertyGrid and passing in an Object for the user to make changes, what is the best approach for handling a cancel/undo.

Do you provide a copy of the original object into the property grid make your changes then if the user accepts the mods then update the values into the original object?

Make a copy of the original settings and pass in the live object and if they cancel, move back the original values?

Or some other approach?

A: 

Any and all can work; for simple objects, the approach I've used most commonly (in that scenario) is serialization to create a deep-clone without needing to maintain any code. If you need to undo, just deserialize the snapshot. However, this works best if the object you want to undo isn't already in 27 properties and collections scattered over the model; in that scenario you might have to do a lot more work.

Marc Gravell
cool thanks I thought I was doing it the right way, it's just the project that I've inherited is driving me insane with it's obscure settings management. I guess I just need to invest some time making it work properly now :-(
Paul Farry