Undo / Redo with undomadeeasy

  • Posted on: 19 December 2010
  • By: markus.wilhelm

I created a new .Net application and found a genious library for implementing Undo / Redo functionality to. You can find the trial version at http://www.undomadeeasy.com/

For the better usage I created a helper class which is downloadable in our download store. The helper class currently offers the following helper methods:

How to use this class:
Import this class to your project. Just copy and paste the needed line to your event handlers or wherever you need it.


Special Handlign for DataGridView Table:
Working with dataGridView only works if you assigned a DataTable object as the Databinding for this datagridview. It is necessary
to have the column rowPosition (visible = false), this offers the posibility to add and remove rows in the middle of the table.
dataGridView1_BindingTable is of type DataTable

For tables it is with this class not possible to work with AllowUserToAddRow and AllowUserToDeleteRow. If you would use this you must work with Event handlers newrow and deletedrow and this will cause a loop. I was not able to solve this. If you have any idea feel free to enhance.

1) Add a new row
DataRow row = dataGridView1_BindingTable.NewRow();
row["xxxx"] = "";
.... (all other new columns values)
row["rowPosition"] = dataGridview.CurrentRow.Index;

2) Remove an existing row
UndoHelperClass.Instance.changeTableDeleteRow(dataGridView1_BindingTable, dataGridView1.CurrentRow.Index, true);

3) Change Cell values inside a Table
The old cell value can be stored using the event dataGridView1_CellEnter

UndoHelperClass.Instance.changeTableUpdateCell(dataGridView1_BindingTable, dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, oldvalue, dataGridView1.CurrentCell.Value.ToString());