I am using C# in Visual Studio 2015 to add Tasks to MS Project and change the outline level. While I am able to add tasks, I am getting run-time error when I try to change the OutlineLevel
. I found out that the Task.OutlineLevel
is a short
and so I tried several things to cast to short
- nothing worked. Here is the code.
private void button_Taskcount_Click(object sender, EventArgs e)
{
Int16 level;
// label_counttasks.Text = myProject.Name + "has " + myProject.Tasks.Count + " tasksom" ;
MSProject.Project myProject = Globals.ThisAddIn.Application.ActiveProject;
MSProject.Task myTask;
myTask = myProject.Tasks.Add("New Task");
myTask = myProject.Tasks.Add("New Task 2",myTask.UniqueID);
level = (Int16)(myTask.OutlineLevel + 1);
myTask.OutlineLevel = level;
}
I get an error that says "The argument is invalid". I have spent 6 hours on it..
I want to change the outline level of myTask
. I also tried myTask.OutlineIndent()
- it gives the same error.
Answering my own question after 6 more hours of searching. It turns out that I was trying to change the outlinelevel of the first task, which is not allowed. For the second task I was adding, I was using the "before" parameter as the first task. So the task was added as the first task. So when I tried to change the outline level of the added task (which is now the first task), it complained, as expected, as you cannot make the outline level of the first task greater than 1.