Data Source
- 3 minutes to read
The GanttControl.DataSource property allows you to specify the control’s data source.
Field Names
The following properties specify data source fields that contain the data required by the control to display the project schedule (hierarchy, dates, dependencies, etc.):
Hierarchy
- GanttControl.TreeListMappings.KeyFieldName — Gets or sets the name of the key field that uniquely identifies records in the data source. This data source field must store unique values.
- GanttControl.TreeListMappings.ParentFieldName — Gets or sets the data source field that identifies each record’s parent.
Tasks
- GanttControl.ChartMappings.TextFieldName — Gets or sets the data source field that specifies a task’s text.
- GanttControl.ChartMappings.StartDateFieldName — Gets or sets the data source field that specifies a task’s start date.
- GanttControl.ChartMappings.FinishDateFieldName — Gets or sets the data source field that specifies a task’s finish date.
- GanttControl.ChartMappings.DurationFieldName — Gets or sets the data source field that specifies a task’s duration.
- GanttControl.ChartMappings.ProgressFieldName — Gets or sets the data source field that specifies a task’s progress.
Baselines
- GanttControl.ChartMappings.BaselineStartDateFieldName — Gets or sets the data source field that specifies a task’s baseline start date. The baseline start field shows the planned beginning date for a task.
- GanttControl.ChartMappings.BaselineFinishDateFieldName — Gets or sets the data source field that specifies a task’s baseline finish date. The baseline finish field shows the planned completion date for a task.
- GanttControl.ChartMappings.BaselineDurationFieldName — Gets or sets the data source field that specifies a task’s baseline duration. The baseline duration field shows the original span of time planned to complete a task.
Baselines are only displayed if the GanttControl.OptionsView.ShowBaselines option is enabled.
Dependencies
- GanttControl.ChartMappings.PredecessorsFieldName — Gets or sets the data source field that specifies a task’s predecessors. This field contains ID keys for predecessor tasks on which the current task depends.
How to Create Data Source in Code
The code below shows how to initialize tree list and chart mappings.
GanttControl ganttControl = new GanttControl();
ganttControl.TreeListMappings.KeyFieldName = "Id";
ganttControl.TreeListMappings.ParentFieldName = "ParentId";
ganttControl.ChartMappings.TextFieldName = "Name";
ganttControl.ChartMappings.StartDateFieldName = "StartTime";
ganttControl.ChartMappings.FinishDateFieldName = "EndTime";
ganttControl.ChartMappings.ProgressFieldName = "Progress";
ganttControl.ChartMappings.PredecessorsFieldName = "PredecessorIDs";
ganttControl.DataSource = Task.GetData();
public class Task {
public int Id { get; set; }
public int ParentId { get; set; }
//
public string Name { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public TimeSpan Duration { get; set; }
public double Progress { get; set; }
//
public IReadOnlyList<int> PredecessorIDs {
get; private set;
}
}
Note
Run the Gantt Code Examples demo to see the complete example.