Skip to main content
All docs
V25.1
  • Bind to Data Source

    • 6 minutes to read

    DevExpress data controls support ADO.NET, Entity Framework, eXpress Persistent Objects, and other data access technologies. You can also bind a data control to an IList, IBindingList, or ITypedList object. See the following topics for more information: Traditional Data Binding Methods and Data Binding Common Concepts.

    This topic explains mappings between data fields in the main data source and task properties. The GanttControl also supports additional data sources that allow you to store information about dependencies (of multiple types) and split tasks. See the following topics for more information: Task Dependencies and Split a Partially Completed Task.

    Main Data Source

    The DataSource property specifies the control’s main data source. The tables below contain data fields that the data source should include to display a project such as hierarchy, dates, and dependencies.

    Note

    Make sure that you specified all required mappings. Otherwise, specific functionality may not be available.

    Task List Area Mappings

    The TreeListMappings property specifies data fields that contain parent-child relationships between tasks.

    Field

    Description

    Default Field Name

    Property that Specifies the Field Name

    Data Type

    Key

    A data field that contains a task’s unique identifier.

    “ID”

    KeyFieldName

    Object

    Parent’s Key

    A data field that contains a parent task’s unique identifier. Use this data field to specify hierarchy.

    “ParentID”

    ParentFieldName

    Object

    Chart Area Mappings

    The ChartMappings property specifies data fields that contain information about bars in the chart area.

    Field

    Description

    Default Field Name

    Property that Specifies the Field Name

    Data Type

    Start Date

    A data field that contains a task’s start date.

    “StartDate”

    StartDateFieldName

    DateTime

    Finish Date

    A data field that contains a task’s finish date. You can use either Finish Date or Duration.

    “FinishDate”

    FinishDateFieldName

    DateTime

    Duration

    A data field that contains a task’s duration. You can use either Duration or Finish Date.

    Empty

    DurationFieldName

    TimeSpan

    Text

    A data field that contains a caption displayed next to a task in the chart. Note that this field does not have a default name. You must specify it to display task captions in the chart.

    Empty

    TextFieldName

    String

    Tooltip Text

    A data field that contains a task’s caption in tooltips. Note that this field does not have a default name. You must specify it to display task captions in tooltips.

    Empty

    InteractionTooltipTextFieldName

    String

    Progress

    A data field that contains a task’s completion percentage.

    “Progress”

    ProgressFieldName

    Single

    Baselines

    Baselines allow you to display a task’s planned start and finish dates, and duration. Note that baselines are only displayed if the ShowBaselines option is enabled. See the following topic for more information: Task Baselines.

    Field

    Description

    Default Field Name

    Property that Specifies the Field Name

    Data Type

    Baseline Start Date

    A data field that contains a baseline’s start date.

    “BaselineStartDate”

    BaselineStartDateFieldName

    DateTime

    Baseline Finish Date

    A data field that contains a baseline’s finish date. You can use either Baseline Finish Date or Baseline Duration.

    “BaselineFinishDate”

    BaselineFinishDateFieldName

    DateTime

    Baseline Duration

    A data field that contains a baseline’s duration. You can use either Baseline Duration or Baseline Finish Date. Note that this field does not have a default name. You must specify it to specify baseline durations.

    Empty

    BaselineDurationFieldName

    TimeSpan

    Dependencies

    The main data source supports the finish-to-start dependency type only. To specify other dependency types, you should use an additional data source. You also cannot specify a time lag between dependent tasks if you use the main data source to store dependencies. See the following topic for more information: Task Dependencies.

    Field

    Description

    Default Field Name

    Property that Specifies the Field Name

    Data Type

    Predecessors

    A data field that contains a task’s predecessors. The field should contain predecessor keys separated by a space, comma, or semicolon (‘ ‘, ‘,’ ‘;’).

    “Predecessors”

    PredecessorsFieldName

    String, IList

    Task Constraints

    Task constraints allow you to limit a task’s start or finish date to a specific date or date range.

    Field

    Description

    Default Field Name

    Property that Specifies the Field Name

    Data Type

    Constraint Type

    A data field that contains the constraint types (As Soon As Possible, Start No Earlier Than, and so on).

    “ConstraintType”

    ConstraintTypeFieldName

    ConstraintType, Int32

    Limit Date

    A data field that contains the limit date.

    “ConstraintDate”

    ConstraintDateFieldName

    DateTime

    See the following topic for more information: Task Constraints.

    Example

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

    image

    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;
    }
    
    See Also