Hi Niels,
As per the information provided by the developers, creating Command directly is not supported officially. This can be confirmed from the fact that the Command class is marked with EditorBrowsable(EditorBrowsableState.Never). It means that Command class is used for internal logic and is not intended to expose it to user.
However, you can create a combined action which execute and undo all commands at once. Because Command is used internally at this time, the solution may have problem for some rare scenario or may not work with other types of commands. Here is the sample code for the same:
[code]CombinedAction action = new CombinedAction(
[
new CellEditCommand(fpSpread1.ActiveSheet.AsWorksheet(), 0, 0, 0, 0, "ABC", false, 0),
new CellEditCommand(fpSpread1.ActiveSheet.AsWorksheet(), 1, 0, 1, 0, "DEF", false, 0),
new CellEditCommand(fpSpread1.ActiveSheet.AsWorksheet(), 2, 0, 2, 0, "1+2", false, 0, false, 0),
new CellEditCommand(fpSpread1.ActiveSheet.AsWorksheet(), 3, 0, 3, 0, "3+4", false, 0, false, 0)
]);
fpSpread1.UndoManager.PerformUndoAction(action);
public class CombinedAction : FarPoint.Win.Spread.UndoRedo.UndoAction
{
private Command[] _commands;
public CombinedAction(Command[] commands)
{
_commands = commands;
}
public override bool PerformUndoAction(object sender)
{
SpreadView spreadView = sender as SpreadView;
GrapeCity.Spreadsheet.Workbook workbook = (GrapeCity.Spreadsheet.Workbook)spreadView.Owner.AsWorkbook();
for (int i = 0; i < _commands.Length; i++)
{
CommandResult result = _commands[i].Execute(workbook);
if (!result.Success)
{
return false;
}
}
return true;
}
protected override bool SaveUndoState()
{
for (int i = 0; i < _commands.Length; i++)
{
_commands[i].SaveUndoState();
}
return true;
}
public override bool Undo(object sender)
{
SpreadView spreadView = sender as SpreadView;
GrapeCity.Spreadsheet.Workbook workbook = (GrapeCity.Spreadsheet.Workbook)spreadView.Owner.AsWorkbook();
for (int i = 0; i < _commands.Length; i++)
{
CommandResult result = _commands[i].Undo();
if (!result.Success)
{
return false;
}
}
return true;
}
}
[/code]
Kindly refer to the attached sample for full implementation. See
UndoManagerSample_Mod.zip
Thanks & Regards,
Aastha