Undoing event

Posted by: kbj on 18 February 2024, 8:25 am EST

  • Posted 18 February 2024, 8:25 am EST

    Is there an event that fires when an undo is happening? In my app, I suspend updating my custom data model while rows and columns are being dragged by handling the RowDragMoveCompleting and RowDragMoveCompleted events. But when the move is “undone”, no event is fired. Is there a way to know that the user is requesting an Undo?

    -Kingman

  • Posted 18 February 2024, 4:59 pm EST

    Hi Kingman,

    FpSpread.UndoManager’s UndoComplete event is fired when an undo action is done on the FpSpread control. You can handle the above-mentioned event as shown in the following code snippet to achieve your requirement:

    fpSpread1.UndoManager.UndoComplete += (s, e) =>
    {
        MessageBox.Show("Action undone");
    };
    

    Kindly refer to the attached sample for full implementation. See UndoHandle.zip

    Thanks & Regards,

    Aastha

  • Posted 18 February 2024, 11:06 pm EST

    HI Aastha,

    I don’t think the above solves the problem. When I do a row drag drop I protect the DataModel with the following:

        Private Sub wb_RowDragMoveCompleting(sender As Object, e As DragMoveCompletedEventArgs) Handles wb.RowDragMoveCompleting
                 worksheet.wsDataModel.suspendUpdate()
        End Sub
        Private Sub wb_RowDragMoveCompleted(sender As Object, e As DragMoveCompletedEventArgs) Handles wb.RowDragMoveCompleted
                worksheet.wsDataModel.resumeUpdate()
         End Sub

    There is no “UndoCompleting” event in the UndoManager. I think it would be helpful to have an event announcing the start of some undo task which would give the opportunity to cancel the task or do the above suspending.

    Kingman

  • Posted 19 February 2024, 5:27 pm EST

    Hello Kingman,

    You can use the RowDragMove event handler that the user drags to move a row and handle it accordingly.

    We have attached a stripped-down sample handling these events; please see if it helps.

    If it does not align with your requirements, please update the sample accordingly and let us know the steps to reproduce.

    Regards,

    Prabhat Sharma.

    SpreadUndoTest.zip

  • Posted 20 February 2024, 3:19 am EST

    Prabhat,

    Please read my first entry in this topic. My problem is not with dragging, it is with undoing a drag. I am looking for an event that fires before an undo happens to suspend updating the data model and then resumes when the undo is complete.

    -Kingman

  • Posted 20 February 2024, 4:27 pm EST

    Hello Kingman,

    Apologies for misunderstanding the issue.

    As there is no such event “UndoCompleting” available in the API, you can use the PreviewKeyDown and Sheet’s RowChanged events in order to capture action before undoing.

    Please see the following code and let us know if it helps:

    fpSpread1.PreviewKeyDown += FpSpread1_PreviewKeyDown;
     fpSpread1.RowDragMoveCompleted += FpSpread1_RowDragMoveCompleted;
     fpSpread1.Sheets[0].RowChanged += Form1_RowChanged;
    
      bool undoRowDrag = false;
      private void FpSpread1_RowDragMoveCompleted(object sender, FarPoint.Win.Spread.DragMoveCompletedEventArgs e)
      {
         worksheet.wsDataModel.resumeUpdate();
      }
    
      private void Form1_RowChanged(object sender, FarPoint.Win.Spread.SheetViewEventArgs e)
      {
          if (undoRowDrag)
          {
              worksheet.wsDataModel.suspendUpdate();
              undoRowDrag = false;
          }
      }
    
      private void FpSpread1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
      {
          if(e.Control && e.KeyCode == Keys.Z)
          {
              undoRowDrag = true;        
          }
      }

    Please let us know if it helps.

    Regards,

    Prabhat Sharma.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels