none
Application.OnUndoOrRedo(bstrLabel, bstrGUID, fUndo) event is not firing as expected RRS feed

  • Question

  • I am using Visual Studio Tools For office, with Visual Studio 2010 to customize Microsoft Project 2010 using C#.

    The runtime version for the Interop Assembly is: v2.0.50727

    There is an event on the Application Object:

    documented here: http://msdn.microsoft.com/en-us/library/ff864594.aspx

    Application.OnUndoOrRedo(bstrLabel, bstrGUID, fUndo)

    My code looks as below: 

      private void ThisAddIn_Startup(object sender, EventArgs e)
            {
                
                initializeLogging();
                Application.OnUndoOrRedo += new _EProjectApp2_OnUndoOrRedoEventHandler(Application_OnUndoOrRedo);
    }
    
     void Application_OnUndoOrRedo(string bstrLabel, string bstrGUID, bool fUndo)
            {
                //throw new NotImplementedException();
            }

    This event is not being fired when I try to undo a transaction.

    This same question was asked here:

    http://social.technet.microsoft.com/Forums/en-US/project2010custprog/thread/e87a1bb0-9890-461f-8029-54a3f0989fcb/

    But with no answer.

    Is this a known problem?

    Am I doing something wrong?

    Any help would be appreciated.


    Thursday, February 9, 2012 8:26 PM

Answers

  • Thomas,

    Good news, after investigate on this question further, I found the trick. That is:

    1. People need to use OpenUndoTransaction and CloseUndoTransaction method together with the event; referring to: http://msdn.microsoft.com/en-us/library/ff864594.aspx
    2. We need to specify Guid parameter for OpenUndoTransaction method, this is required. Code sample looks like below:
    public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                //Application.OpenUndoTransaction("task");
    
                //Sub CreateTasksWithUndoTransaction() 
                //ActiveProject.Tasks.Add "Task outside transaction" 
                //Application.OpenUndoTransaction "Create 6 tasks" 
                //Dim i As Integer 
                //For i = 1 To 6 
                //    ActiveProject.Tasks.Add "UndoMe " & i 
                //Next 
                //Application.CloseUndoTransaction  
                //End Sub 
    
                CreateTasksWithUndoTransaction();
    
                Application.OnUndoOrRedo += new MSProject._EProjectApp2_OnUndoOrRedoEventHandler(Application_OnUndoOrRedo);
    
            }
    
            void Application_OnUndoOrRedo(string bstrLabel, string bstrGUID, bool fUndo)
            {
                Application.StatusBar = bstrLabel + " undo or redo";
            }
    
            private void CreateTasksWithUndoTransaction()
            {
                Application.ActiveProject.Tasks.Add("Task outside transaction");
    
                Application.OpenUndoTransaction("Create 6 tasks", "{A5797E62-C816-4DEC-ADA8-11A8C3A6DEB7}");
    
                for (int i = 1; i <= 6; i++)
                {
                    Application.ActiveProject.Tasks.Add("UndoMe " + i.ToString());
                }
                Application.CloseUndoTransaction();
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }


    Forrest Guo | MSDN Community Support | Feedback to us

    Wednesday, February 15, 2012 6:25 AM
    Moderator

All replies

  • Should I report this as a bug, if so where do I do that? Surely somebody has a suggestion or a workaround to this problem.
    Monday, February 13, 2012 2:24 PM
  • Thomas,

    I'm looking into this issue. And I could reproduce the behavior as you mentioned. However, I'd like to double-check this with other professional before we move to next step.

    Best Regards, 


    Forrest Guo | MSDN Community Support | Feedback to us

    Wednesday, February 15, 2012 3:26 AM
    Moderator
  • Thomas,

    Good news, after investigate on this question further, I found the trick. That is:

    1. People need to use OpenUndoTransaction and CloseUndoTransaction method together with the event; referring to: http://msdn.microsoft.com/en-us/library/ff864594.aspx
    2. We need to specify Guid parameter for OpenUndoTransaction method, this is required. Code sample looks like below:
    public partial class ThisAddIn
        {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                //Application.OpenUndoTransaction("task");
    
                //Sub CreateTasksWithUndoTransaction() 
                //ActiveProject.Tasks.Add "Task outside transaction" 
                //Application.OpenUndoTransaction "Create 6 tasks" 
                //Dim i As Integer 
                //For i = 1 To 6 
                //    ActiveProject.Tasks.Add "UndoMe " & i 
                //Next 
                //Application.CloseUndoTransaction  
                //End Sub 
    
                CreateTasksWithUndoTransaction();
    
                Application.OnUndoOrRedo += new MSProject._EProjectApp2_OnUndoOrRedoEventHandler(Application_OnUndoOrRedo);
    
            }
    
            void Application_OnUndoOrRedo(string bstrLabel, string bstrGUID, bool fUndo)
            {
                Application.StatusBar = bstrLabel + " undo or redo";
            }
    
            private void CreateTasksWithUndoTransaction()
            {
                Application.ActiveProject.Tasks.Add("Task outside transaction");
    
                Application.OpenUndoTransaction("Create 6 tasks", "{A5797E62-C816-4DEC-ADA8-11A8C3A6DEB7}");
    
                for (int i = 1; i <= 6; i++)
                {
                    Application.ActiveProject.Tasks.Add("UndoMe " + i.ToString());
                }
                Application.CloseUndoTransaction();
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }


    Forrest Guo | MSDN Community Support | Feedback to us

    Wednesday, February 15, 2012 6:25 AM
    Moderator
  • Thank you so much, that was it.
    Wednesday, February 15, 2012 1:29 PM