How to assign parent to child task in code

M

Mike

I think what I want to do is pretty simple, but my attempts are causing COM
exception. I want the first task I add to be the Summary task and then I want
each successive task I add to become the child of the summary task.

In c# I am trying this
// first task is parent
MSProject.Task parent= _thisProject.Tasks[projectRow["JobName"]];
....
while(moreTasks)
{
...
MSProject.Task child=_thisProject.Tasks.Add(taskName.ToString(),
Type.Missing);

// assign parent to child
child.Parent = parent; // causes "Unexpected error occurred with the method"
}

Thanks
 
M

Mike

I figured this out. First of all the Parent property is Read-Only. I find it
curious that this code compiled in the first place.

Anyway, for anyone else new to this Project programming, i had to set the
OutLinelevel property of all the child tasks to 2. This had the desired
result.
 
J

Jan De Messemaeker

Hi
More in general, if the Level isn't 2, there is the OutlineIndent method.

--
Jan De Messemaeker
Microsoft Project MVP
http://users.online.be/prom-ade
Mike said:
I figured this out. First of all the Parent property is Read-Only. I find
it
curious that this code compiled in the first place.

Anyway, for anyone else new to this Project programming, i had to set the
OutLinelevel property of all the child tasks to 2. This had the desired
result.
--
Mike


Mike said:
I think what I want to do is pretty simple, but my attempts are causing
COM
exception. I want the first task I add to be the Summary task and then I
want
each successive task I add to become the child of the summary task.

In c# I am trying this
// first task is parent
MSProject.Task parent= _thisProject.Tasks[projectRow["JobName"]];
....
while(moreTasks)
{
...
MSProject.Task child=_thisProject.Tasks.Add(taskName.ToString(),
Type.Missing);

// assign parent to child
child.Parent = parent; // causes "Unexpected error occurred with the
method"
}

Thanks
 
M

Mike

Jan:

I tried that method and it did indeed indent the task, the problem was that
each addtional task continued to be indented so I ended up with something
like this:

Task A
Task B
Task C
Task D
... and so on

rather than

Task A
Task B
Task C
Task D

Thanks for your reply..

--
Mike


Jan De Messemaeker said:
Hi
More in general, if the Level isn't 2, there is the OutlineIndent method.

--
Jan De Messemaeker
Microsoft Project MVP
http://users.online.be/prom-ade
Mike said:
I figured this out. First of all the Parent property is Read-Only. I find
it
curious that this code compiled in the first place.

Anyway, for anyone else new to this Project programming, i had to set the
OutLinelevel property of all the child tasks to 2. This had the desired
result.
--
Mike


Mike said:
I think what I want to do is pretty simple, but my attempts are causing
COM
exception. I want the first task I add to be the Summary task and then I
want
each successive task I add to become the child of the summary task.

In c# I am trying this
// first task is parent
MSProject.Task parent= _thisProject.Tasks[projectRow["JobName"]];
....
while(moreTasks)
{
...
MSProject.Task child=_thisProject.Tasks.Add(taskName.ToString(),
Type.Missing);

// assign parent to child
child.Parent = parent; // causes "Unexpected error occurred with the
method"
}

Thanks
 
J

Jan De Messemaeker

Hi,
A task is inserted at the level of the task above it, so you need Outline
indent only once in your case.

--
Jan De Messemaeker
Microsoft Project MVP
http://users.online.be/prom-ade
Mike said:
Jan:

I tried that method and it did indeed indent the task, the problem was
that
each addtional task continued to be indented so I ended up with something
like this:

Task A
Task B
Task C
Task D
... and so on

rather than

Task A
Task B
Task C
Task D

Thanks for your reply..

--
Mike


Jan De Messemaeker said:
Hi
More in general, if the Level isn't 2, there is the OutlineIndent method.

--
Jan De Messemaeker
Microsoft Project MVP
http://users.online.be/prom-ade
Mike said:
I figured this out. First of all the Parent property is Read-Only. I
find
it
curious that this code compiled in the first place.

Anyway, for anyone else new to this Project programming, i had to set
the
OutLinelevel property of all the child tasks to 2. This had the desired
result.
--
Mike


:

I think what I want to do is pretty simple, but my attempts are
causing
COM
exception. I want the first task I add to be the Summary task and then
I
want
each successive task I add to become the child of the summary task.

In c# I am trying this
// first task is parent
MSProject.Task parent= _thisProject.Tasks[projectRow["JobName"]];
....
while(moreTasks)
{
...
MSProject.Task child=_thisProject.Tasks.Add(taskName.ToString(),
Type.Missing);

// assign parent to child
child.Parent = parent; // causes "Unexpected error occurred with the
method"
}

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top