Skip to main content

Tasks, Summaries, and Milestones

  • 3 minutes to read

The GanttControlNode class represents a node in the task list. The control automatically determines a task’s type based on its duration and the presence of subtasks. The following task types are supported:

  • Task — a regular task that has a certain duration and does not have subtasks.

    image

  • Summary task — a task that has subtasks. These tasks show combined information for their subtasks.

    image

  • Milestone — a task with a zero duration. These tasks show important dates in the project.

    image

The control also displays dependencies between tasks. A task can have a predecessor task that should be accomplished before the task can start. The figure below illustrates different task types and dependencies between them.

Task Captions

A task can have captions displayed inside, to the left, and to the right of the bar. Handle the GanttControl.CustomTaskDisplayText event to show captions.

The code below shows how to display captions to the left and to the right of the bars.

image

HashSet<int> criticalPathIds = new HashSet<int> { 1, 2, 3, 6, 7, 8, 10, 11, 13 };
ganttControl.CustomTaskDisplayText += (sender, e) => {
    int taskId = Convert.ToInt32(e.Node.GetValue("Id"));
    if(criticalPathIds.Contains(taskId)) {
        e.RightText = "High priority";
    }
    else {
        e.RightText = string.Empty;
        e.LeftText = "Normal priority";
    }
};

Note

Run the Gantt Code Examples demo to see the complete example.

Context Menus

When a user right-clicks a task’s bar, the control can show a context menu. To populate the menu with commands, handle the GanttControl.TaskPopupMenuShowing event.

The code below shows how to populate the context menu with items.

using DevExpress.XtraEditors;
using DevExpress.XtraGantt;

private void ganttControl1_TaskPopupMenuShowing(object sender, GanttTaskPopupMenuShowingEventArgs e) {
    e.Items.Add(new DevExpress.Utils.Menu.DXMenuItem("Show Text", (ss, ee) => { XtraMessageBox.Show(e.Node.GetText()); }));
}

Tooltips

To show a tooltip for a task, handle GanttControl.TaskToolTipShowing event.

The code below shows a regular tooltip for a task.

using DevExpress.XtraGantt;

private void ganttControl1_TaskToolTipShowing(object sender, GanttTaskToolTipShowingEventArgs e) {
    e.Text = e.Node.GetText();
}

Draw a Task Manually

You can handle the following events to draw a task manually:

The code below shows how to highlight specific tasks and dependencies.

image

Run Demo: Highlight Tasks and Dependencies

HashSet<int> tasks = new HashSet<int> { 1, 2, 3, 6, 7, 8, 10, 11, 13 };
ganttControl.CustomDrawTask += (sender, e) => {
    int taskId = Convert.ToInt32(e.Node.GetValue("Id"));
    if(tasks.Contains(taskId)) {
        e.Appearance.BackColor = DXSkinColors.FillColors.Warning;
        e.Appearance.ProgressColor = DXSkinColors.FillColors.Warning;
    }
};
ganttControl.CustomDrawTaskDependency += (sender, e) => {
    int predecessorId = Convert.ToInt32(e.PredecessorNode.GetValue("Id"));
    int successorId = Convert.ToInt32(e.SuccessorNode.GetValue("Id"));
    if(tasks.Contains(predecessorId) && tasks.Contains(successorId)) {
        e.Appearance.BackColor = DXSkinColors.FillColors.Warning;
    }
};