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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to programatically Determine if Grid can Undo/Redo?

Thread ID:

Created:

Updated:

Platform:

Replies:

119913 Aug 13,2015 12:51 AM UTC Aug 17,2015 07:39 AM UTC Windows Forms 5
loading
Tags: GridControl
Alan Burkhart
Asked On August 13, 2015 12:51 AM UTC

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.

Thanks
AB

Mahendran Annamalai [Syncfusion]
Replied On 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.

http://help.syncfusion.com/ug/windows%20forms/index.html#!documents/thebasics.htm

Sample:  VB


Please let us know if you have any concerns.

Regards,

Mahendran.A


Alan Burkhart
Replied On 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.

Mahendran Annamalai [Syncfusion]
Replied On 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.



Thanks,

Mahendran.A


Alan Burkhart
Replied On August 16, 2015 02:21 PM UTC

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

Mahendran Annamalai [Syncfusion]
Replied On August 17, 2015 07:39 AM UTC

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;