View Single Post
Old May 20th, 2014, 03:13 PM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

Hmm... that may be a bit tricky.

In general to add undo/redo functionality you create a stack of undo actions. To undo, you move the most recent action off of that stack and add it to a redo stack. To redo, you do the opposite.

That gets a lot more complicated if you use more powerful controls such as DataGridView. Those controls tend to have their own ideas about what undo and redo mean. For example, in a normal TextBox undo cycles between the last twp things you typed. (Or to think of it another way, the last thing you typed and whatever was there before you typed that.)

The DataGridView does provide some support via the underlying DataSet and DataTable objects. Take a look at these posts and see if they help.

I'm not sure how easy they are to use with EF. You might need to look more closely at the classes and modify their property procedures to create the necessary objects in the undo/redo stacks.

I think most applications just ignore this issue and only let the user cancel or commit changes. They don't provide a more fine-grained undo/redo.

I hope that helps.

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
shabnamzangeneh (May 20th, 2014)