找回密码
 立即注册

QQ登录

只需一步,快速开始

sff1001

注册会员

1

主题

2

帖子

19

积分

注册会员

积分
19
最新发帖
sff1001
注册会员   /  发表于:2018-11-23 15:48  /   查看:3877  /  回复:7
文档没看明白(http://help.grapecity.com/spread ... spwin-undoredo.html),
如何做删除行和插入行的撤销呢(C#版)?这个不应该是默认操作吗。。。

论坛里搜索了下,看到有如下网址,结果打不开。
http://gcdn.grapecity.com/showto ... ;postid=40355#40355

望帮助。

7 个回复

倒序浏览
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-11-23 17:14:30
沙发
本帖最后由 dexteryao 于 2018-11-23 17:16 编辑

https://gcdn.grapecity.com.cn/forum.php?mod=viewthread&tid=8511,路径如下。对于用户的UI操作是可以Undo的,但是这种代码的操作,需要自己实现undo
回复 使用道具 举报
sff1001
注册会员   /  发表于:2018-11-24 00:09:30
板凳
dexteryao 发表于 2018-11-23 17:14
https://gcdn.grapecity.com.cn/forum.php?mod=viewthread&tid=8511,路径如下。对于用户的UI操作是可以Und ...

1、自己实现的UnDo能添加到Ctrl+Z的撤销列表里吗?
2、能实现像Excel一样的撤销功能:比如:行删除(自定义UnDo)、行新增(自定义Undo)、单元格输入、单元格编辑(代码改变值)、单元格清除、单元格样式设置等全部使用Ctrl+Z进行撤销,并且是按顺序。
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-11-26 13:36:57
地板
撤销的堆栈是自动的,只要在action 里实现了undo逻辑,调用的时候会按照执行的反顺序undo。
行删除行新增需要自定义实现undo其他操作都不需要。
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-11-26 13:37:00
5#
撤销的堆栈是自动的,只要在action 里实现了undo逻辑,调用的时候会按照执行的反顺序undo。
行删除行新增需要自定义实现undo其他操作都不需要。
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-11-26 16:09:14
6#

  1.     public class AddRowAction : FarPoint.Win.Spread.UndoRedo.UndoAction
  2.     {
  3.         int row, rowCount;
  4.         public AddRowAction()
  5.         {
  6.             this.row = 0;
  7.             this.rowCount = 1;
  8.         }

  9.         public AddRowAction(int row, int rowCount)
  10.         {
  11.             this.row = row;
  12.             this.rowCount = rowCount;
  13.         }
  14.         protected override bool SaveUndoState()
  15.         {
  16.             return true;
  17.         }

  18.         public override bool Undo(object sender)
  19.         {
  20.             if (sender is FarPoint.Win.Spread.SpreadView)
  21.             {
  22.                 FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
  23.                 FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
  24.                 sheet.RemoveRows(this.row, this.rowCount);

  25.             }

  26.             return true;
  27.         }

  28.         public override bool PerformUndoAction(object sender)
  29.         {
  30.             if (sender is FarPoint.Win.Spread.SpreadView)
  31.             {
  32.                 FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
  33.                 FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
  34.                 sheet.AddRows(this.row, this.rowCount);
  35.                 return true;
  36.             }
  37.             return false;
  38.         }

  39.     }
  40.     public class DeleteRowAction : FarPoint.Win.Spread.UndoRedo.UndoAction
  41.     {
  42.         int row, rowCount;
  43.         FarPoint.Win.Spread.SheetView sheet;
  44.         object[,] deleteData;
  45.         public DeleteRowAction()
  46.         {
  47.             this.row = 0;
  48.             this.rowCount = 1;
  49.         }

  50.         public DeleteRowAction(int row, int rowCount)
  51.         {
  52.             this.row = row;
  53.             this.rowCount = rowCount;
  54.         }
  55.         protected override bool SaveUndoState()
  56.         {
  57.             this.deleteData = this.sheet.GetArray(row, 0, rowCount, this.sheet.ColumnCount);
  58.             return true;
  59.         }

  60.         public override bool Undo(object sender)
  61.         {
  62.             if (sender is FarPoint.Win.Spread.SpreadView)
  63.             {
  64.                 FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
  65.                 FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
  66.                 sheet.AddRows(this.row, this.rowCount);
  67.                 sheet.SetArray(row, 0, this.deleteData);

  68.             }

  69.             return true;
  70.         }

  71.         public override bool PerformUndoAction(object sender)
  72.         {
  73.             if (sender is FarPoint.Win.Spread.SpreadView)
  74.             {
  75.                 FarPoint.Win.Spread.SpreadView spread = (FarPoint.Win.Spread.SpreadView)sender;
  76.                 FarPoint.Win.Spread.SheetView sheet = spread.Sheets[spread.ActiveSheetIndex];
  77.                 this.sheet = sheet;
  78.                 this.SaveUndoState();

  79.                 sheet.RemoveRows(this.row, this.rowCount);
  80.                 return true;
  81.             }
  82.             return false;
  83.         }

  84.     }


复制代码


  1. //var addRowAction = new AddRowAction(1, 2);
  2. //fpSpread1.UndoManager.PerformUndoAction(addRowAction);

  3. var deleteRowAction = new DeleteRowAction(1, 2);
  4. fpSpread1.UndoManager.PerformUndoAction(deleteRowAction);
复制代码


回复 使用道具 举报
大卫
注册会员   /  发表于:2022-9-21 19:50:32
7#
dexteryao 发表于 2018-11-26 13:36
撤销的堆栈是自动的,只要在action 里实现了undo逻辑,调用的时候会按照执行的反顺序undo。
行删除行新增 ...

如何自定义呢
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2022-9-22 15:09:04
8#
楼上给的就是自定义新增和删除行的undo
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部