Skip to main content

GanttControl.DependencyMappings Property

Provides access to names of data fields mapped to dependency properties (type, time lag, predecessor, and successor).

Namespace: DevExpress.XtraGantt

Assembly: DevExpress.XtraGantt.v23.2.dll

NuGet Package: DevExpress.Win.Gantt

Declaration

[XtraSerializableProperty(XtraSerializationVisibility.Content, XtraSerializationFlags.DefaultValue)]
public GanttDependencyMappings DependencyMappings { get; }

Property Value

Type Description
GanttDependencyMappings

An object that maps data source fields to task properties.

Remarks

The KeyFieldName property specifies the data field that stores a task’s unique identifier (key). These keys are used to specify dependencies between tasks.

Finish-to-Start Dependencies

The control’s DataSource property allows you to bind the control to a data source. The ChartMappings property provides access to data fields mapped to task properties that specify how a task is displayed in the chart area. The PredecessorsFieldName property specifies the data field that stores keys of task predecessors. Note that this data field allows you to specify finish-to-start dependencies only without time lag.

ganttControl1.ChartMappings.PredecessorsFieldName = "Predecessors";

The data field can be of the following types:

  • String — the string should contain keys separated by space, comma, or semicolon (‘ ‘, ‘,’ ‘;’).

  • IEnumerable — the enumerator should return key values of the same type as the key field.

    For example, an IList object allows users to modify dependencies and save changes to the data source. The collection should not be read only.

Dependencies of Any Types

The DependencySource property allows you to bind the control to a data source that can store dependencies. Note that this additional data source allows you to specify dependencies of any type (finish-to-start, finish-to-finish, and so on) and any time lags.

If the data source contains multiple tables, use the DataMember property to specify the table that contains dependencies.

The DependencyMappings property allows you to specify data fields that should be mapped to dependency properties:

ganttControl1.DependencyMappings.PredecessorFieldName = "Predecessor";
ganttControl1.DependencyMappings.SuccessorFieldName = "Successor";
ganttControl1.DependencyMappings.TypeFieldName = "Type";
ganttControl1.DependencyMappings.LagFieldName = "Lag";

See the following topic for more information: Task Dependencies.

Obtain or Set Dependencies in Code

Use the following methods to obtain an object that contains data for a specific dependency:

To specify the node in the method’s parameter, use the node’s Id property value.

The SetDependency(GanttControlNode, GanttControlNode, DependencyType, TimeSpan) method allows you to specify a dependency in code.

Example

The code below shows how to specify tasks and dependencies.

image

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;
}
See Also