Back to Devexpress

GanttChartMappings.PredecessorsFieldName Property

windowsforms-devexpress-dot-xtragantt-dot-ganttchartmappings-c408de06.md

latest10.5 KB
Original Source

GanttChartMappings.PredecessorsFieldName Property

Gets or sets the data source field that specifies a task’s predecessors. The data field should contain an IList object or a String value with keys separated by space, comma, or semicolon (‘ ‘, ‘,’ ‘;’).

Namespace : DevExpress.XtraGantt

Assembly : DevExpress.XtraGantt.v25.2.dll

NuGet Package : DevExpress.Win.Gantt

Declaration

csharp
[DefaultValue("Predecessors")]
[DXCategory("Mappings")]
[XtraSerializableProperty]
public string PredecessorsFieldName { get; set; }
vb
<DXCategory("Mappings")>
<DefaultValue("Predecessors")>
<XtraSerializableProperty>
Public Property PredecessorsFieldName As String

Property Value

TypeDefaultDescription
String"Predecessors"

The data source field that specifies a task’s predecessors.

|

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.

csharp
ganttControl1.ChartMappings.PredecessorsFieldName = "Predecessors";
vb
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.

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:

csharp
ganttControl1.DependencyMappings.PredecessorFieldName = "Predecessor";
ganttControl1.DependencyMappings.SuccessorFieldName = "Successor";
ganttControl1.DependencyMappings.TypeFieldName = "Type";
ganttControl1.DependencyMappings.LagFieldName = "Lag";
vb
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.

csharp
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;
}
vb
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()

Private Function GetTasks() As DataTable
    Dim table As New DataTable()
    Dim id As New DataColumn("ID", GetType(Integer))
    Dim parentId As New DataColumn("ParentID", GetType(Integer))
    Dim taskText As New DataColumn("Text", GetType(String))
    Dim start As New DataColumn("StartDate", GetType(DateTime))
    Dim finish As New DataColumn("FinishDate", GetType(DateTime))
    Dim predecessors As New DataColumn("Predecessors", GetType(String))
    table.Columns.AddRange(New DataColumn() {id, parentId, taskText, start, finish, predecessors})
    table.Rows.Add(New Object() { 1, 0, "Task 1", DateTime.Now, DateTime.Now.AddDays(1), Nothing })
    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(1), DateTime.Now.AddDays(2), "1, 2" })
    Return table
End Function

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PredecessorsFieldName property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-win-gantt-control/CS/XPO/GanttSolutionXPO/GanttSolutionXPO.Win/Editors/CustomGanttEditor.cs#L83

csharp
control.ChartMappings.ProgressFieldName = nameof(IMyTask.Progress);
control.ChartMappings.PredecessorsFieldName = nameof(IMyTask.PredecessorTasks);
control.AllowTouchGestures = DevExpress.Utils.DefaultBoolean.True;

See Also

DependencyMappings

DependencySource

Task Dependencies

GanttChartMappings Class

GanttChartMappings Members

DevExpress.XtraGantt Namespace