Skip to main content

Task Baselines

  • 6 minutes to read

The control supports task baselines — a task’s start and finish dates, and its duration captured at a certain moment. A user can compare a task’s current date and duration with its baselines to track changes as the project progresses. Baselines can be used to indicate a schedule agreed at the start of a project.

Tip

Run the following demo to see baselines: Startup Plan.

Enable Baselines and Bind to Data Source

To display baselines in the chart, enable the ShowBaselines option. To specify data source fields that contain baselines, use the following properties:

Use the BaselineFinishDateFieldName or BaselineDurationFieldName property, depending on the data source and the fields it contains. If you specify both properties, the control uses the finish date.

Example: Reset Baselines

The example below shows how to display a command in the ribbon that resets all the baselines.

The code calls the DoOperation method to enumerate tasks and reset baselines. Use the control’s NodesIterator property to access the enumerator.

The following code uses a BarButtonItem and handles its ItemClick event to display a command in the ribbon:

using System;
using System.ComponentModel;
using System.Collections.Generic;
//Enable baselines.
ganttControl1.OptionsView.ShowBaselines = true;
//Specify data fields that contain baselines.
ganttControl1.ChartMappings.BaselineDurationFieldName = "BaselineDuration";
ganttControl1.ChartMappings.BaselineStartDateFieldName = "BaselineStartDate";
ganttControl1.ChartMappings.BaselineFinishDateFieldName = "BaselineFinishDate";

ganttControl1.TreeListMappings.KeyFieldName = "Id";
ganttControl1.TreeListMappings.ParentFieldName = "ParentId";
ganttControl1.ChartMappings.TextFieldName = "Name";
ganttControl1.ChartMappings.StartDateFieldName = "StartDate";
ganttControl1.ChartMappings.FinishDateFieldName = "FinishDate";
ganttControl1.ChartMappings.DurationFieldName = "Duration";
ganttControl1.ChartMappings.PredecessorsFieldName = "Predecessors";
ganttControl1.ChartMappings.ProgressFieldName = "Progress";
ganttControl1.DataSource = LoadData();
//...
public static IList<Task> LoadData() {
    var tasks = new List<Task>();
    Task softwareDevelopment = new Task("Software Development", 0, -1, DateTime.Now, 1, 24);
    Task analyseRequirements = new Task("Analyse Requirements", 1, softwareDevelopment.Id, softwareDevelopment.StartDate, 1, 100);
    Task developFunctionalSpecifications = new Task("Develop functional specifications", 2, softwareDevelopment.Id, analyseRequirements.FinishDate, 1, 100, 1);
    Task developSoftware = new Task("Develop software", 3, softwareDevelopment.Id, developFunctionalSpecifications.FinishDate, 5, 40, developFunctionalSpecifications.Id);
    Task developHelpSystem = new Task("Develop help system", 4, softwareDevelopment.Id, developFunctionalSpecifications.FinishDate, 1, 90, developFunctionalSpecifications.Id);
    Task developUserManuals = new Task("Develop user manuals", 5, softwareDevelopment.Id, developHelpSystem.FinishDate, 1, 0, developHelpSystem.Id);
    Task testSoftware = new Task("Test software", 6, softwareDevelopment.Id, developSoftware.FinishDate, 2, 0, developSoftware.Id);
    Task deployBeta = new Task("Deploy Beta", 7, softwareDevelopment.Id, testSoftware.FinishDate, 0, 0, testSoftware.Id);
    Task collectFeedback = new Task("Collect feedback", 8, softwareDevelopment.Id, deployBeta.FinishDate, 2, 0, deployBeta.Id);
    Task fixBugs = new Task("Fix bugs", 9, softwareDevelopment.Id, collectFeedback.FinishDate, 2, 0, collectFeedback.Id);
    Task incorporateFeedBack = new Task("Incorporate feedback", 10, softwareDevelopment.Id, collectFeedback.FinishDate, 3, 0, collectFeedback.Id);
    Task releaseSoftware = new Task("Release software", 11, softwareDevelopment.Id, incorporateFeedBack.FinishDate, 2, 0, fixBugs.Id, incorporateFeedBack.Id);
    Task createSoftwareMaintenanceTeam = new Task("Create software maintenance team", 12, softwareDevelopment.Id, deployBeta.FinishDate, 1, 0, developSoftware.Id);
    Task softwareDevelopmentComplete = new Task("Software development complete", 13, softwareDevelopment.Id, releaseSoftware.FinishDate, 0, 0, releaseSoftware.Id);
    softwareDevelopment.FinishDate = softwareDevelopmentComplete.FinishDate;
    tasks.AddRange(new Task[] {softwareDevelopment, analyseRequirements, developFunctionalSpecifications, developSoftware, developHelpSystem, developUserManuals,
        testSoftware,deployBeta,collectFeedback, fixBugs, incorporateFeedBack, releaseSoftware, createSoftwareMaintenanceTeam, softwareDevelopmentComplete });
    return tasks;
}
//Respond to clicks on the 'Set Baselines' ribbon command (created in the designer).
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    ganttControl1.NodesIterator.DoOperation(node => {
        //Reset baselines.
        node.SetValue("BaselineStartDate", node.GetValue("StartDate"));
        node.SetValue("BaselineFinishDate", node.GetValue("FinishDate"));
    });
    ganttControl1.RefreshDataSource();
}
//...
public class Task{
    public Task(string name, int id, int parentId, DateTime start, int duration, double progress, params int[] predecessors) {
        Name = name;
        Id = id;
        ParentId = parentId;
        StartDate = start;
        Duration = TimeSpan.FromDays(duration);
        FinishDate = start + Duration;
        Progress = progress;
        Predecessors = new BindingList<int>();
        foreach (int predecessor in predecessors) {
           Predecessors.Add(predecessor);
        }
        //Initialize baselines.
        BaselineFinishDate = FinishDate;
        BaselineStartDate = StartDate;
    }
    //Declare baseline data fields.
    public DateTime BaselineStartDate { get; set; }
    public DateTime BaselineFinishDate { get; set; }
    public TimeSpan Duration { get; set; }

    public int Id { get; set; }
    public int ParentId { get; set; }
    public BindingList<int> Predecessors { get; private set; }
    public string Name { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime FinishDate { get; set; }
    public double Progress { get; set; }
}