How do I listen for a Project Change event from an MS Project VSTO Add-in?

天大地大妈咪最大 提交于 2020-01-06 04:07:54

问题


My Add-in has an application event ProjectBeforeTaskChange that is available from the ThisAddIn class. What I need is a ProjectAfterTaskChange event, but that doesn't exist. Is there a way to listen for the Project Change event from an application level add-in?

My end goal is to set three number fields when a specific text field changes.


回答1:


ProjectBeforeTaskChange is the correct event to use to monitor field changes. The word "Before" refers to the fact that the handler can prevent the change by setting the Cancel argument to True. The event is triggered when the user makes a change to a task field.

Here's a vb.net example that increments the Number1 and Number2 fields whenever the Text1 field changes:

Private Sub Application_ProjectBeforeTaskChange(tsk As MSProject.Task, Field As MSProject.PjField, NewVal As Object, ByRef Cancel As Boolean) Handles Application.ProjectBeforeTaskChange

    If Field = MSProject.PjField.pjTaskText1 Then
        Select Case NewVal
            Case Is = "In-work": tsk.Number1 = 50
            Case Is = "Complete": tsk.Number1 = 100
            Case Else: tsk.Number1 = 0
        End Select
    End If
End Sub

Here's the MSDN page.

Here's a related post showing the c# framework.



来源:https://stackoverflow.com/questions/48686672/how-do-i-listen-for-a-project-change-event-from-an-ms-project-vsto-add-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!