How to Create Tasks in Gantt View in Code
- 2 minutes to read
The ExpressScheduler provides the following API that allows you to build a task plan in Gantt View programmatically:
TcxSchedulerEvent.TaskComplete – specifies the task completion percentage.
TcxSchedulerEvent.TaskIndex – specifies the current task’s vertical position relative to other tasks.
TcxSchedulerEvent.TaskStatus – specifies the task status.
TcxSchedulerEvent.TaskLinks – represents task links that belong to the current task.
TcxSchedulerEventLinks.Add – adds a new connector.
TcxSchedulerEventItemLink.Relation – specifies the connector type.
TcxSchedulerGanttView.EventsStyle – specifies whether completion percentage is to be displayed in tasks.
TcxSchedulerGanttView.ShowTotalProgressLine – specifies whether a progress line is to be displayed in Gantt View.
TcxSchedulerGanttView.ShowExpandButtons – specifies whether task expand buttons are to be displayed in Gantt View.
The following example demonstrates how to create tasks in Gantt View using this API:
// ...
var
I: Integer;
APreEvent, AEvent: TcxSchedulerEvent;
begin
APreEvent := nil;
for I := 1 to 10 do
begin
AEvent := Scheduler.Storage.createEvent;
with AEvent do
begin
Caption := IntToStr(I);
Start := Trunc(Date * 24) / 24;
Duration := 1 / 24 + Trunc(RandomRange(1, 5)) / 24;
TaskComplete := RandomRange(0, 100);
Post;
TaskLinks.Add(APreEvent, TcxSchedulerEventRelation(RandomRange(0, 3)));
end;
APreEvent := AEvent;
end;
end;
The following image shows the code execution result:
The following image shows the task completion percentage (if the scheduler’s ViewGantt.EventsStyle property is esProgress):