.net – PropertyGrid and Providing Undo – Education Career Blog

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?


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.

Leave a Comment