We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to programatically Determine if Grid can Undo/Redo?

I'm using a class derived from GridControl to build an editor for very large delimited text files. The program includes an "UpdateUI" sub that updates the menu and toolstrip to enable/disable various items - for example disabling the Cut menu item if CutPaste.CanCut is False. I have not seen a method for doing this with Undo/Redo. How do I determine if the grid is able to perform an Undo or Redo operation? VB.Net would be appreciated.


5 Replies

MA Mahendran Annamalai Syncfusion Team August 13, 2015 12:44 PM UTC

Hi Alan,

Thanks for using Syncfusion products.            

To handle the Undo/Redo operations in GridControl, you can set CommandStack.Enabled property.

Please find below code example for your reference.

' Disable Undo/Redo operations.

Me.gridControl1.CommandStack.Enabled = False

Similar information have been discussed in the below UG and sample below.


Sample:  VB

Please let us know if you have any concerns.



AB Alan Burkhart August 13, 2015 02:09 PM UTC

You misunderstood the question. The CommandStack will always be enabled in the application. What I wish to know is how to find out if an Undo or Redo operation is available so I can update the tool bar buttons accordingly. For example, when I first open a file, no Undo/Redo operations would be available because the file has not changed. So, both the Undo and Redo buttons would be disabled. But once I edit the file, then an Undo operation is available, so the Undo button would be enabled. If I Undo the change to the file, returning the file to its original state, then the Undo button should be disabled and the Redo button would be enabled.

What I need to know is how to find out if an Undo or Redo operation can be performed so I can update the UI accordingly. With clipboard operations I can use the grid's CanCut and CanPaste properties to enable or disable tool bar buttons. I just need to know how  to access similar functionality for Undo/Redo in the grid.

MA Mahendran Annamalai Syncfusion Team August 14, 2015 11:20 AM UTC

Hi Alan,

Thanks for your update.

To enable or disable buttons based on Undo/Redo operations, it can be done by checking  CommandStack.UndoStack property. If the count of CommandStack is greater than zero, you can enable or disable those buttons. Please find the code snippet below.

Private Sub gridControl1_CellsChanged(ByVal sender As Object, ByVal e As GridCellsChangedEventArgs)

      'Enabling or disabling Undo and Redo buttons.

      If Me.gridControl1.CommandStack.UndoStack.Count > 0 Then

            Me.BtnUndo.Enabled =Me.gridControl1.CommandStack.UndoStack.Count > 0

      End If

      If Me.gridControl1.CommandStack.RedoStack.Count > 0 Then

            Me.btnRedo.Enabled = Me.gridControl1.CommandStack.RedoStack.Count > 0

      End If

End Sub

Sample: UndoRedo_VB

Please let me know of you have any concerns.



AB Alan Burkhart August 16, 2015 02:21 PM UTC

That solved my problem. Can't imagine why I missed it in the documentation. Many thanks!

MA Mahendran Annamalai Syncfusion Team August 17, 2015 07:39 AM UTC

Hi Alan,
Thanks for your update.
Please let us know if you need further assistance.

Live Chat Icon For mobile
Up arrow icon