Back to Devexpress

Split a Partially Completed Task

windowsforms-401975-controls-and-libraries-gantt-control-split-tasks.md

latest7.0 KB
Original Source

Split a Partially Completed Task

  • Sep 22, 2022
  • 4 minutes to read

The GanttControl supports split tasks — tasks with interruptions. A user can drag a task’s uncompleted segment to split the task. The user can split a task into as many segments as needed.

If a task is split, the user can resize and move all of its segments. If the user drags the first segment, the control moves all segments. Any other segment can be moved separately.

Run Demo

Automatic Scheduling

If the ScheduleMode option is set to Auto, the control can split a task due to changes in the project. For example, if a partially completed task should be postponed, the control splits the completed and uncompleted parts.

If the ScheduleMode option is set to Manual, users can split partially completed tasks but the control does not automatically split tasks.

See the following topic for more information: Automatic Scheduling.

Allow Split Tasks & API

The AllowSplitTasks option specifies whether the control and users can split tasks.

csharp
ganttControl1.OptionsBehavior.AllowSplitTasks = DevExpress.Utils.DefaultBoolean.True;
vb
ganttControl1.OptionsBehavior.AllowSplitTasks = DevExpress.Utils.DefaultBoolean.True

Use the following API to split tasks in code:

Data Source

The SplitTaskSource property specifies a data source that contains information about interruptions, their start dates, and durations. Use the SplitTaskMappings property to specify data fields that contain corresponding information:

Important

If the SplitTaskSource property is not specified, split tasks are not allowed even if the AllowSplitTasks option is enabled.

How Splits Affect Task Finish Date and Duration

A task has a start date, finish date, and duration. To specify a task’s location on the time scale, you only need two of them: start and finish, or start and duration. See the following help topic for more information on how to specify the data fields that contain corresponding values: Bind to Data Source. The control calculates the unspecified parameter (duration or finish date) when tasks are loaded from the data source as follows:

  • If you have specified the start and finish dates — task splits reduce the duration but do not change the finish date.
  • If you have specified the start date and duration — task splits postpone the finish date but do not change the duration.

Note that after tasks are loaded (finish dates/durations are calculated), the control can only update the finish date (but not the duration) when a task’s split duration is changed.

Example

The code below shows a sample data source that contains information about task splits.

csharp
ganttControl1.SplitTaskMappings.StartDateFieldName = "StartDate";
ganttControl1.SplitTaskMappings.DurationFieldName = "Duration";
ganttControl1.SplitTaskMappings.KeyFieldName = "UID";

List<TaskSplitInfo> splitInfo = new List<TaskSplitInfo>();
splitInfo.Add(new TaskSplitInfo() { UID = "8", StartDate = tasks[8].StartDate + TimeSpan.FromHours(2), Duration = TimeSpan.FromHours(8)});
splitInfo.Add(new TaskSplitInfo() { UID = "9", StartDate = tasks[9].StartDate + TimeSpan.FromHours(5), Duration = TimeSpan.FromDays(1)});
splitInfo.Add(new TaskSplitInfo() { UID = "10", StartDate = tasks[10].StartDate + TimeSpan.FromHours(4), Duration = TimeSpan.FromHours(4) });
splitInfo.Add(new TaskSplitInfo() { UID = "10", StartDate = tasks[10].StartDate + TimeSpan.FromDays(2) + TimeSpan.FromHours(2), Duration = TimeSpan.FromHours(4) });
ganttControl1.SplitTaskSource = splitInfo;

public class TaskSplitInfo {
    public string UID { get; set; }
    public DateTime StartDate { get; set; }
    public TimeSpan Duration { get; set; }
}
vb
ganttControl1.SplitTaskMappings.StartDateFieldName = "StartDate"
ganttControl1.SplitTaskMappings.DurationFieldName = "Duration"
ganttControl1.SplitTaskMappings.KeyFieldName = "UID"

Dim splitInfo As New List(Of TaskSplitInfo)()
splitInfo.Add(New TaskSplitInfo() With {.UID = "8", .StartDate = tasks(8).StartDate.Add(TimeSpan.FromHours(2)), .Duration = TimeSpan.FromHours(8)})
splitInfo.Add(New TaskSplitInfo() With {.UID = "9", .StartDate = tasks(9).StartDate.Add(TimeSpan.FromHours(5)), .Duration = TimeSpan.FromDays(1)})
splitInfo.Add(New TaskSplitInfo() With {.UID = "10", .StartDate = tasks(10).StartDate.Add(TimeSpan.FromHours(4)), .Duration = TimeSpan.FromHours(4)})
splitInfo.Add(New TaskSplitInfo() With {.UID = "10", .StartDate = tasks(10).StartDate.Add(TimeSpan.FromDays(2).Add(TimeSpan.FromHours(2))), .Duration = TimeSpan.FromHours(4)})
ganttControl1.SplitTaskSource = splitInfo

Public Class TaskSplitInfo
    Public Property UID() As String
    Public Property StartDate() As Date
    Public Property Duration() As TimeSpan
End Class