All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Task Constraints

  • 7 minutes to read

A task constraint allows a user to limit a task’s start or finish date to a specific date or range of dates. The task’s start or finish date always remains in the specified range regardless of changes in the project.

For example, the release date of a product’s new version is a certain date or later. If development and testing are postponed, this shifts the release to a later date. However, if development and testing are completed earlier, the release remains at the same date.

Gantt Control Task Constraints

Run Demo: Software Development module in the XtraGantt GanttDemo

Constraint Types

The table below contains supported constraints.

Constraint Name

Value

Description

Type

AsSoonAsPossible

0

The task should start as soon as possible. This is the default constraint.

Flexible

AsLateAsPossible

1

The task should start as late as possible but it should not delay other tasks so that they violate their constraints.

Flexible

StartNoEarlierThan

2

The task’s start date should be later than or equal to the specified date.

Semi-Flexible

StartNoLaterThan

3

The task’s start date should be earlier than or equal to the specified date.

Semi-Flexible

FinishNoEarlierThan

4

The task’s finish date should be later than or equal to the specified date.

Semi-Flexible

FinishNoLaterThan

5

The task’s finish date should be earlier than or equal to the specified date.

Semi-Flexible

MustStartOn

6

The task’s start date should be equal to the specified date.

Non-Flexible

MustFinishOn

7

The task’s finish date should be equal to the specified date.

Non-Flexible

Flexible Constraints

The As Soon As Possible (ASAP) and As Late As Possible (ALAP) constraints are flexible, which means that they do not require a date. The control schedules a task based on dependencies between this task and its predecessors and successors.

As Soon As Possible is the default constraint. It is typically applied to tasks if the project should finish as quickly as possible.

The As Late As Possible constraint can be applied to a task if its successor should start later than this task normally finishes. For example, if supplies need to be delivered to the factory just-in-time before production to reduce storage costs, a user can apply the ALAP constraint to this task.

Semi-Flexible Constraints

The Start No Later Than (SNLT), Start No Earlier Than (SNET), Finish No Later Than (FNLT), and Finish No Earlier Than (FNET) constraints are semi-flexible, which means that they limit the task to a specific date, but this date is the upper or lower limit of possible values.

For example, the Start No Earlier Than constraint limits a task’s start date to a specific range of dates. That is if a user modifies other tasks in the project, the control can reschedule this task to start on the specified or later date.

Note

The control automatically applies the Start No Earlier Than or Finish No Earlier Than constraint if a user changes a task’s start or finish date, accordingly. See more information below.

Non-Flexible Constraints

The Must Start On and Must Finish On constraints are non-flexible, which means they require an exact start or finish date.

Note

Semi-flexible and non-flexible constraints require a date. If the constraint date is not specified, the control automatically applies the current start or finish date depending on the constraint’s type. For example, if a user applies the Must Start On constraint to a task but does not specify the constraint date, the control uses the current start date.

Data Source

Users can apply constraints to tasks if the data source contains fields for this information. The following properties specify the field names:

See the following topic for more information on how to specify the data source: Bind to Data Source.

Example

The code below shows how to specify constraints in code. The Must Start On constraint applies to the third task and the As Late As Possible constraint applies to the second task.

Gantt Control Task Constraints

using DevExpress.XtraGantt;
using System.Data;

ganttControl1.TreeListMappings.KeyFieldName = "ID";
ganttControl1.TreeListMappings.ParentFieldName = "ParentID";
ganttControl1.ChartMappings.TextFieldName = "Text";
ganttControl1.ChartMappings.StartDateFieldName = "StartDate";
ganttControl1.ChartMappings.FinishDateFieldName = "FinishDate";
ganttControl1.ChartMappings.ConstraintTypeFieldName = "ConstraintType";
ganttControl1.ChartMappings.ConstraintDateFieldName = "ConstraintDate";
ganttControl1.DataSource = GetTasks();

ganttControl1.DependencyMappings.PredecessorFieldName = "PredecessorID";
ganttControl1.DependencyMappings.SuccessorFieldName = "SuccessorID";
ganttControl1.DependencyMappings.TypeFieldName = "DependencyType";
ganttControl1.DependencyMappings.LagFieldName = "TimeLag";
ganttControl1.DependencySource = GetDependencies();

DataTable GetTasks() {
    DataTable table = new DataTable();
    DataColumn id = new DataColumn("ID", typeof(int));
    DataColumn parentId = new DataColumn("ParentID", typeof(int));
    DataColumn text = new DataColumn("Text", typeof(string));
    DataColumn start = new DataColumn("StartDate", typeof(DateTime));
    DataColumn finish = new DataColumn("FinishDate", typeof(DateTime));
    DataColumn constraintType = new DataColumn("ConstraintType", typeof(ConstraintType));
    DataColumn constraintDate = new DataColumn("ConstraintDate", typeof(DateTime));

    table.Columns.AddRange(new DataColumn[] { id, parentId, text, start, finish , constraintType, constraintDate });
    table.Rows.Add(new object[] { 1, 0, "Task 1", DateTime.Now, DateTime.Now.AddDays(1) , null, null });
    table.Rows.Add(new object[] { 2, 0, "Task 2", DateTime.Now.AddDays(2), DateTime.Now.AddDays(3) , ConstraintType.AsLateAsPossible, null  });
    table.Rows.Add(new object[] { 3, 0, "Task 3", DateTime.Now.AddDays(3), DateTime.Now.AddDays(4) , ConstraintType.MustStartOn, DateTime.Now.AddDays(3) });
    return table;
}

DataTable GetDependencies() {
    DataTable table = new DataTable();
    DataColumn predecessor = new DataColumn("PredecessorID", typeof(int));
    DataColumn successor = new DataColumn("SuccessorID", typeof(int));
    DataColumn dependencyType = new DataColumn("DependencyType", typeof(DevExpress.XtraGantt.DependencyType));
    DataColumn lag = new DataColumn("TimeLag", typeof(TimeSpan));
    table.Columns.AddRange(new DataColumn[] { predecessor, successor, dependencyType, lag });
    table.Rows.Add(new object[] { 1, 2, DependencyType.FinishToStart, null });
    table.Rows.Add(new object[] { 2, 3, DependencyType.FinishToStart, null });
    return table;
}

Apply Constraints Automatically

The control automatically applies the Start No Earlier Than constraint to a task if a user changes its start date and the Finish No Earlier Than constraint if a user changes its finish date.

If a user moves a task in the chart, the Start No Earlier Than constraint applies to a regular task and the Finish No Earlier Than constraint applies to a milestone.

Set the ConstraintMode property to Manual to allow users to apply constraints manually, but not automatically.

using DevExpress.XtraGantt.Options;

ganttControl1.OptionsBehavior.ConstraintMode = ConstraintMode.Manual;

Limitations

Constraints cannot be applied to summary tasks. If the project uses task constraints, users cannot move summary tasks in automatic scheduling mode.