Parent and Child Tasks
Contents
[
Hide
Show
]Tasks can be organized in a hierarchy. When a task has one or more tasks beneath it, they are referred to as parents. The tasks underneath are called children.
Working with Parent Tasks and Children
The Task class exposes classes that help you determine a:
- Parent: determines that a task is a parent task. Accepts and returns a Task object.
- Children: determines that a task is a child task. Accepts and returns an array list of Task objects.
Parent and Child Tasks in Microsoft Project
To declare a task as a parent or a child task in Microsoft Project:
- In the Task Entry form, select a task and click it.
- Select Outdent to turn a task into a parent, or,
- Select Indent to turn a task into a child.
Getting Parent and Child Tasks
The following examples show viewing parent and child tasks in a project using Aspose.Tasks.
1// Create project instance
2System::String dataDir = RunExamples::GetDataDir(System::Reflection::MethodBase::GetCurrentMethod(ASPOSE_CURRENT_FUNCTION)->get_DeclaringType().get_FullName());
3System::SharedPtr<Project> project1 = System::MakeObject<Project>(dataDir + u"ParentChildTasks.mpp");
4
5// Create a ChildTasksCollector instance
6System::SharedPtr<ChildTasksCollector> collector = System::MakeObject<ChildTasksCollector>();
7
8// Collect all the tasks from RootTask using TaskUtils
9TaskUtils::Apply(project1->get_RootTask(), collector, 0);
10
11// Parse through all the collected tasks
12
13{
14 auto tsk1_enumerator = (collector->get_Tasks())->GetEnumerator();
15 decltype(tsk1_enumerator->get_Current()) tsk1;
16 while (tsk1_enumerator->MoveNext() && (tsk1 = tsk1_enumerator->get_Current(), true))
17 {
18 System::Console::WriteLine(tsk1->Get(Tsk::Name()));
19 }
20}