wpf-400337-controls-and-libraries-gantt-control-bind-to-data-bind-to-selfreference-data.md
This topic covers binding the GanttControl to self-reference data structures.
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.
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; }
}
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.
Refer to the Task Dependencies topic for more information on how to retrieve task dependencies from the data source.