Hi
I'm writing a simple application that connects a WinGrid to a database table (via an EntitySpaces business object) and allows the user to update, edit and delete records.
I have almost all the functionality in place but one other thing I am doing is keeping a count of each change, delete and insert to display to the user at the top of the screen and it is also used to determine if the Save, Undo or Redo buttons are enabled. I also highlight the changed cells / inserted rows or not, to show what has changed.
The problem is that I need to know what the Undo / Redo 'events' are changing so that I can change my totals / (un)highlight cells accordingly, and if there is nothing to Undo / Redo, disable the relevant button(s).
I'm using the following commands in my Undo / Redo button OnClick event handlers:
myGrid.PerformAction(UltraGridAction.Undo);
myGrid.PerformAction(UltraGridAction.Redo);
However, I can't find any events related to something like OnUndo / OnRedo to intercept what is being changed so I can decrease / increase my totals accordingly.
Also I'm using the 'AfterCellUpdate', 'AfterRowInsert' and 'AfterRowsDeleted' event handlers to increment my totals but they also get updated after the Undo / Redo as I don;t know the logic needed to check if its an Undo taking place.
Some object must be keeping track of the changes for the Undo / Redo to work, but I can't seem to find it.
Can anyone help?
Cheers
You might also want to look at the BeforeMultiCellOperation event.
Ok cheers for the response, I'm certainly seeing an Undo action but I'm getting a bit confused on what would be the correct action for my desired functionality of having a running total of unsaved changes that is incremented/decremented when changing and undoing specific changes.
I have three attributes defined to store the number of unsaved Adds, Changes and Deletions in the grid:
private int _iUnsavedChanged; private int _iUnsavedDeleted; private int _iUnsavedAdded; private int _iToDelete;
which are updated in the following events, which works until you undo something.
private void grdSiteRegister_AfterCellUpdate(object sender, CellEventArgs e) { if (e.Cell.Value != e.Cell.OriginalValue) this._iUnsavedChanged++; } private void grdSiteRegister_AfterRowInsert(object sender, RowEventArgs e) { this._iUnsavedAdded++; } private void grdSiteRegister_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e) { this._iToDelete = e.Rows.Length; } private void grdSiteRegister_AfterRowsDeleted(object sender, EventArgs e) { this._iUnsavedDeleted+= this._iToDelete; }
I'm not 100% sure on how best to use the events suggested to decrement these totals on undo, if someone could post a sample event handler it would be appreciated.