)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to enable or disable buttons based on undo or redo operations in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: August 14, 2015 |
Last Revised Date: December 20, 2019
Tags: undoredo

Undo redo operation

To enable or disable buttons based on the Undo or Redo operations, check the CommandStack.UndoStack and CommandStack.Redo properties. When the count of the CommandStack is greater than zero, you can enable or disable those buttons.

The following code demonstrates the same.

C#

void gridControl1_CellsChanged(object sender, GridCellsChangedEventArgs e)
{
    //Enables or disables Undo and Redo buttons.
    if (this.gridControl1.CommandStack.UndoStack.Count > 0)
    {
        this.BtnUndo.Enabled =this.gridControl1.CommandStack.UndoStack.Count > 0 ;
    }
    if (this.gridControl1.CommandStack.RedoStack.Count > 0)
    {
        this.btnRedo.Enabled = this.gridControl1.CommandStack.RedoStack.Count > 0;
    }
}

 

VB

Private Sub gridControl1_CellsChanged(ByVal sender As Object, ByVal e As GridCellsChangedEventArgs)
    'Enables or disables 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

 

Samples:

C#: UndoRedo_C#

VB: UndoRedo_VB

Reference link: https://help.syncfusion.com/windowsforms/grid-control/undo-redo

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon