All docs
V20.1
20.2 (EAP/Beta)
20.1
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 Dependencies

  • 5 minutes to read

The Gantt control can display task dependencies of the following types:

  • FinishToStart — a successor should start when its predecessor finishes.

  • FinishToFinish — a successor should finish when its predecessor finishes.

  • StartToFinish — a successor should finish when its predecessor starts.

  • StartToStart — a successor should start when its predecessor starts.

How to Specify Dependencies

To specify dependencies, use data source fields. If you only need finish-to-start dependencies, you can use the same data source for tasks and dependencies. If you need all dependency types, use a separate data source for dependencies.

Finish-to-Start Dependency Type

If you only need the finish-to-start dependency type, use the GanttControl.DataSource property to specify the data source that contains tasks and dependencies. A data record represents a task and contains information about its caption, start and finish dates, duration, and predecessors. The GanttControl.ChartMappings property provides access to the PredecessorsFieldName property to specify a task's predecessors.

The code below shows how to specify tasks and dependencies.

ganttControl1.TreeListMappings.KeyFieldName = "ID";
ganttControl1.TreeListMappings.ParentFieldName = "ParentID";
ganttControl1.ChartMappings.TextFieldName = "Text";
ganttControl1.ChartMappings.StartDateFieldName = "StartDate";
ganttControl1.ChartMappings.FinishDateFieldName = "FinishDate";
ganttControl1.ChartMappings.PredecessorsFieldName = "Predecessors";
ganttControl1.DataSource = GetTasks();

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 predecessors = new DataColumn("Predecessors", typeof(string));
    table.Columns.AddRange(new DataColumn[] { id, parentId, text, start, finish, predecessors });
    table.Rows.Add(new object[] { 1, 0, "Task 1", DateTime.Now, DateTime.Now.AddDays(1), null });
    table.Rows.Add(new object[] { 2, 0, "Task 2", DateTime.Now.AddDays(1), DateTime.Now.AddDays(2), 1 });
    table.Rows.Add(new object[] { 3, 0, "Task 3", DateTime.Now.AddDays(2), DateTime.Now.AddDays(3), "1, 2"});
    return table;
}

See Data Source for more information about data source mappings.

All Dependency Types

If you need all dependency types, use the GanttControl.DependencySource property to specify the data source that contains dependencies. A data record represents a dependency and specifies its type, predecessor, successor, etc. The GanttControl.DependencyMappings property provides access to the following properties:

  • PredecessorFieldName — specifies a predecessor task's key.
  • SuccessorFieldName — specifies a successor task's key.
  • TypeFieldName — specifies the dependency type (finish-to-start, finish-to-finish, etc.).
  • LagFieldName — specifies the time lag between the successor and the predecessor. If a user moves a predecessor, the control automatically reschedules all its successors with respect to the time lag.
NOTE

If you use these properties and the GanttControl.DependencySource property to specify dependencies, dependencies specified with the PredecessorsFieldName and GanttControl.DataSource properties are not in effect.

The code below shows how to specify tasks and dependencies.

using DevExpress.XtraGantt;

ganttControl1.TreeListMappings.KeyFieldName = "ID";
ganttControl1.TreeListMappings.ParentFieldName = "ParentID";
ganttControl1.ChartMappings.TextFieldName = "Text";
ganttControl1.ChartMappings.StartDateFieldName = "StartDate";
ganttControl1.ChartMappings.FinishDateFieldName = "FinishDate";
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));
    table.Columns.AddRange(new DataColumn[] { id, parentId, text, start, finish });
    table.Rows.Add(new object[] { 1, 0, "Task 1", DateTime.Now, DateTime.Now.AddDays(1) });
    table.Rows.Add(new object[] { 2, 0, "Task 2", DateTime.Now.AddDays(1), DateTime.Now.AddDays(2) });
    table.Rows.Add(new object[] { 3, 0, "Task 3", DateTime.Now.AddDays(2), 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.StartToFinish, new TimeSpan(12, 0, 0) });
    table.Rows.Add(new object[] { 2, 3, DependencyType.StartToStart, null });
    return table;
}

Modify Dependencies

If the AllowModifyDependencies option is enabled, users can modify dependencies. See Interactive Editing and Automatic Scheduling for more information.

See Also