watchaglass watchaglass - 1 month ago 14
C# Question

VSTO add-in for MS Project: display tasks all at once

The code below (in standard ThisAddIn class of a VSTO add-in) retrieves info about tasks to be added to MS Project (2013) and then adds actual tasks to project Tasks collection. The problem is the Project allowing to add tasks one by one and repainting (refreshing) the project view every time a task is added to Tasks collection. It looks annoying. So far I found and used Application.ScreenUpdating property to hide the blinking.

It would be nice to prepare a collection of tasks and attach them all together to the active project. Could anyone more experienced please point towards a way to accomplish this? If it's possible at all with the current MS Project Add-In API?

Thanks a lot.

....
using MSProject = Microsoft.Office.Interop.MSProject;
....

public partial class ThisAddIn
{
....

private void ShowTasks()
{
MSProject.Project project = this.Application.ActiveProject;
// TaskInfo is a custom DTO type
IEnumerable<TaskInfo> dataSource = GetDataSourceSomehow();

this.Application.ScreenUpdating = false;
this.Application.Calculation = MSProject.PjCalculation.pjManual;

foreach(TaskInfo info in dataSource)
{
MSProject.Task task = project.Tasks.Add(info.TaskName);
}

this.Application.ScreenUpdating = true;
}
}

Answer

I took some time investigating but was not successful. Finally i've received an answer that it's not possible, at least with the current API (MS Project 2013):

https://www.add-in-express.com/creating-addins-blog/2014/02/28/creating-and-modifying-ms-project-files-programmatically/#comment-424755

Comments