wpf-400336-controls-and-libraries-gantt-control-bind-to-data-bind-to-hierarchical-data.md
This topic covers binding the GanttControl to hierarchical data structures.
When working with hierarchical data structures, the control’s DataControlBase.ItemsSource property contains only data items that correspond to root nodes (root summary tasks).
A summary task provides access to a collection of its child tasks.
The code sample below demonstrates tasks with the Children property, that returns a collection of task’s children.
public class Task {
public int Id { get; set; }
public string Name { get; set; }
public DateTime Start { get; set; }
public DateTime Finish { get; set; }
public ObservableCollection<Task> Children { get; } = new ObservableCollection<Task>();
}
The GanttControl exposes the ChildNodesPath property that allows you to specify a path to the summary task’s children.
You can bind the GanttControl to hierarchical data source as follows:
<dxgn:GanttControl ItemsSource="{Binding Tasks}">
<dxgn:GanttControl.View>
<dxgn:GanttView
AutoExpandAllNodes="True"
KeyFieldName="Id"
ChildNodesPath="Children"
StartDateMapping="Start"
FinishDateMapping="Finish"
NameMapping="Name"
TreeDerivationMode="ChildNodesSelector">
</dxgn:GanttView>
</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.