Back to Devexpress

Bind to Self-Reference Data

wpf-400337-controls-and-libraries-gantt-control-bind-to-data-bind-to-selfreference-data.md

latest2.1 KB
Original Source

Bind to Self-Reference Data

  • Jun 07, 2019
  • 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

  • Parent Field

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.

csharp
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.

xaml
<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.