Skip to main content
A newer version of this page is available. .

Data Source

  • 4 minutes to read

The GanttControl.DataSource property allows you to specify the control’s data source.

Note that DevExpress data-aware controls are compatible with any data access technology (ADO.NET, Entity Framework, XPO, etc.) and capable to display data from any data source that implements the IList, IBindingList, or ITypedList interface. Refer to these help topics for more details: Traditional Data Binding Methods and Data Binding Common Concepts.

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

Tasks

Baselines

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. The data field should contain an IList object or a String value with keys separated by space, comma, or semicolon (‘ ‘, ‘,’ ‘;’). This field contains ID keys for predecessor tasks on which the current task depends.

This field supports the start-to-finish dependency type only. To specify other dependency types, you should use a separate data source. See Task Dependencies for more information.

How to Create Data Source in Code

The code below shows how to initialize tree list and chart mappings.

ganttControl1.TreeListMappings.KeyFieldName = "ID";
ganttControl1.TreeListMappings.ParentFieldName = "ParentID";
ganttControl1.ChartMappings.TextFieldName = "Text";
ganttControl1.ChartMappings.StartDateFieldName = "StartDate";
ganttControl1.ChartMappings.FinishDateFieldName = "FinishDate";
ganttControl1.ChartMappings.BaselineStartDateFieldName = "BaselineStartDate";
ganttControl1.ChartMappings.BaselineFinishDateFieldName = "BaselineFinishDate";
ganttControl1.OptionsView.ShowBaselines = true;
ganttControl1.ChartMappings.PredecessorsFieldName = "Predecessors";
ganttControl1.DataSource = GetTasks();

DataTable GetTasks() {
    DataTable table = new DataTable();
    DataColumn id = new DataColumn("ID", typeof(int));
    DataColumn parentId = new DataColumn("ParentID", typeof(int));
    DataColumn text = new DataColumn("Text", typeof(string));
    DataColumn start = new DataColumn("StartDate", typeof(DateTime));
    DataColumn finish = new DataColumn("FinishDate", typeof(DateTime));
    DataColumn startBaseline = new DataColumn("BaselineStartDate", typeof(DateTime));
    DataColumn finishBaseline = new DataColumn("BaselineFinishDate", typeof(DateTime));
    DataColumn predecessors = new DataColumn("Predecessors", typeof(string));
    table.Columns.AddRange(new DataColumn[] { id, parentId, text, start, finish, startBaseline, finishBaseline, predecessors });
    table.Rows.Add(new object[] { 1, 0, "Task 1", DateTime.Now, DateTime.Now.AddDays(1), DateTime.Now, DateTime.Now.AddDays(1.5), null });
    table.Rows.Add(new object[] { 2, 0, "Task 2", DateTime.Now.AddDays(1), DateTime.Now.AddDays(2), DateTime.Now.AddDays(1), DateTime.Now.AddDays(1.5), 1 });
    table.Rows.Add(new object[] { 3, 0, "Task 3", DateTime.Now.AddDays(2), DateTime.Now.AddDays(3), DateTime.Now.AddDays(2), DateTime.Now.AddDays(3), "1, 2" });
    return table;
}