Bind to Self-Reference Data

  • 2 minutes to read

This topic covers binding the GanttControl to self-reference data structures.

Self-Reference Data Structure

The GanttControl supports binding to plain data sources.

To represent tasks in a tree structure, the child tasks should reference the parent tasks:

  • Key Field

    This field should contain unique values used to identify nodes. Assign its name to the GanttView's TreeListView.KeyFieldName property.

  • Parent Field

    This field should contain values that indicate parent nodes. Assign its name to the GanttView's TreeListView.ParentFieldName property.

Columns bound to these fields are called service columns, and are not created by default.

The code sample below demonstrates tasks with the Id and ParentId properties, that allow you to organize task hierarchy.

public class Task {
    public int Id { get; set; }
    public int ParentId { get; set; } = -1;
    public string Name { get; set; }
    public DateTime Start { get; set; }
    public DateTime Finish { get; set; }
}

Bind to Self-Reference Data Sources

You can bind the GanttControl to self-reference plain data source by specifying the GanttView's TreeListView.KeyFieldName and the TreeListView.ParentFieldName properties.

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.View>
        <dxgn:GanttView
            AutoExpandAllNodes="True"
            TreeDerivationMode="Selfreference"
            KeyFieldName="Id"
            ParentFieldName="ParentId"
            StartDateMapping="Start"
            FinishDateMapping="Finish"
            NameMapping="Name" />
    </dxgn:GanttControl.View>
</dxgn:GanttControl>

The code sample above demonstrates mapping task properties to data source properties. Refer to the Mappings topic for more information.

Next Steps

Refer to the Task Dependencies topic for more information on how to retrieve task dependencies from the data source.