C# + MS Project

743 views Asked by At

I'm trying to write an application in c#, which select task by means of unique ID. I tried to use several methods. The first with "SelectTPTask" method

using Project = Microsoft.Office.Interop.MSProject;
public static Project.Application prjApp;
public static Project.Project msPrj;

prjApp = new Project.Application();
prjApp.FileOpenEx(Path);
prjApp.Visible = true;
msPrj = prjApp.ActiveProject;

if (msPrj.Tasks != null)
    foreach (Project.Task task in msPrj.Tasks)
    {
        if (task.UniqueID == Id)
        {
            prjApp.SelectTPTask(task.UniqueID);
            //prjApp.SelectRow(task.ID);
        }
    }
    else
    {
        MessageBox.Show("Nothing found");
    }

But it gives an unknown error. The only thing that earned is "SelectRow" method. But it works correctly only once, and then selects the wrong task. But if I restart MS Project, it works correctly 1 time, and then again to choose the wrong tasks.

1

There are 1 answers

0
Rachel Hettinger On BEST ANSWER

The SelectRow method takes several arguments, the second of which indicates if the new selection is relative to the active row; the default is True. Use False for the second argument to select the absolute row.

Application.SelectRow Method (Project)