Articles in this section

How to enable or disable button based on Undo or Redo operations in WinForms GridControl?

Undo Redo operation


To enable or disable Undo/Redo operations, the CommandStack property can be used. The CommandStack maintains the Undo and Redo operations based on the Stack structure.


private void gridControl1_CellsChanged(object sender, GridCellsChangedEventArgs e)
{
   //Enabling or disabling 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;
   }
}
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

The screenshot below shows the undo-redo operations through button clicks.

 

Undo and redo operation in GridControl

 

Samples:

C#Undo_Redo_CS

VBUndo_Redo_VB

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied