- public class AddRowAction : FarPoint.Win.Spread.UndoRedo.UndoAction
- {
- int row, rowCount;
- public AddRowAction()
- {
- this.row = 0;
- this.rowCount = 1;
- }
- public AddRowAction(int row, int rowCount)
- {
- this.row = row;
- this.rowCount = rowCount;
- }
- protected override bool SaveUndoState()
- {
- return true;
- }
- public override bool Undo(object sender)
- {
- if (sender is FarPoint.Win.Spread.SpreadView)
- {
- FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
- FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
- sheet.RemoveRows(this.row, this.rowCount);
- }
- return true;
- }
- public override bool PerformUndoAction(object sender)
- {
- if (sender is FarPoint.Win.Spread.SpreadView)
- {
- FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
- FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
- sheet.AddRows(this.row, this.rowCount);
- return true;
- }
- return false;
- }
- }
- public class DeleteRowAction : FarPoint.Win.Spread.UndoRedo.UndoAction
- {
- int row, rowCount;
- FarPoint.Win.Spread.SheetView sheet;
- object[,] deleteData;
- public DeleteRowAction()
- {
- this.row = 0;
- this.rowCount = 1;
- }
- public DeleteRowAction(int row, int rowCount)
- {
- this.row = row;
- this.rowCount = rowCount;
- }
- protected override bool SaveUndoState()
- {
- this.deleteData = this.sheet.GetArray(row, 0, rowCount, this.sheet.ColumnCount);
- return true;
- }
- public override bool Undo(object sender)
- {
- if (sender is FarPoint.Win.Spread.SpreadView)
- {
- FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
- FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
- sheet.AddRows(this.row, this.rowCount);
- sheet.SetArray(row, 0, this.deleteData);
- }
- return true;
- }
- public override bool PerformUndoAction(object sender)
- {
- if (sender is FarPoint.Win.Spread.SpreadView)
- {
- FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
- FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
- this.sheet = sheet;
- this.SaveUndoState();
- sheet.RemoveRows(this.row, this.rowCount);
- return true;
- }
- return false;
- }
- }
复制代码
- //var addRowAction = new AddRowAction(1, 2);
- //fpSpread1.UndoManager.PerformUndoAction(addRowAction);
- var deleteRowAction = new DeleteRowAction(1, 2);
- fpSpread1.UndoManager.PerformUndoAction(deleteRowAction);
复制代码
|