Skip to main content

Bind to Hierarchical Data

  • 2 minutes to read

This topic covers binding the GanttControl to hierarchical data structures.

Hierarchical Data Structure

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.

Bind to Hierarchical Data Structure

You can bind the GanttControl to hierarchical data source as follows:

  1. Assign the collection of root items to the ItemsSource property.
  2. Assign the child field name to the GanttView’s GanttView.ChildNodesPath property.
  3. Set the TreeDerivationMode property to ChildNodesSelector.
  4. Map the data source field values to task property values.
<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.

Next Steps

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