Back to Devexpress

GanttControl.CustomTaskScheduling Event

windowsforms-devexpress-dot-xtragantt-dot-ganttcontrol-ab7101eb.md

latest6.6 KB
Original Source

GanttControl.CustomTaskScheduling Event

Fires during the automatic rescheduling process when the control calculates new start and finish dates for a task. Allows you to cancel rescheduling the current task and stop the rescheduling process for its successors.

Namespace : DevExpress.XtraGantt

Assembly : DevExpress.XtraGantt.v25.2.dll

NuGet Package : DevExpress.Win.Gantt

Declaration

csharp
[DXCategory("Events")]
public event CustomTaskSchedulingEventHandler CustomTaskScheduling
vb
<DXCategory("Events")>
Public Event CustomTaskScheduling As CustomTaskSchedulingEventHandler

Event Data

The CustomTaskScheduling event's data class is CustomTaskSchedulingEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets whether to cancel rescheduling the processed task and all dependent tasks.
DurationGets or sets the task’s duration.
FinishDateGets or sets the task’s finish date.
NodeGets the processed node.
RowGets an object that specifies the processed data row.
StartDateGets or sets the task’s start date.

Example

The code below shows how to display an unbound column that allows users to specify whether a task should be re-scheduled when its predecessor’s start or finish date changes.

csharp
using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGantt.Options;
using DevExpress.XtraTreeList.Columns;

enum Mode { Manual, Auto };

TreeListColumn colScheduleMode = ganttControl1.Columns.AddField("ScheduleMode");
colScheduleMode.UnboundDataType = typeof(object);
colScheduleMode.Visible = true;
colScheduleMode.AbsoluteIndex = 0;
ganttControl1.TreeListMappings.HierarchyFieldName = "Name";
colScheduleMode.OptionsColumn.AllowSort = false;
colScheduleMode.OptionsColumn.AllowMove = false;
colScheduleMode.Caption = "Task Mode";
RepositoryItemImageComboBox editor = new RepositoryItemImageComboBox();
editor.SmallImages = imageCollection1;
editor.Items.Add(new ImageComboBoxItem("Manually Scheduled", Mode.Manual, 1));
editor.Items.Add(new ImageComboBoxItem("Auto Scheduled", Mode.Auto, 0));
editor.GlyphAlignment = HorzAlignment.Center;
editor.EditValueChanged += (s, e) => { ganttControl1.PostEditor(); };
ganttControl1.RepositoryItems.Add(editor);
colScheduleMode.ColumnEdit = editor;
Dictionary<int, Mode> columnValues = new Dictionary<int, Mode>();
ganttControl1.CustomUnboundColumnData += (sender, e) => {
    if (e.Column.FieldName == "ScheduleMode") {
        if (e.IsGetData) {
            if (!columnValues.ContainsKey(e.NodeID)) {
                columnValues[e.NodeID] = ganttControl1.OptionsBehavior.ScheduleMode == ScheduleMode.Manual ? Mode.Manual : Mode.Auto;
            }
            e.Value = columnValues[e.NodeID];
        }
        if (e.IsSetData && e.Value != null) {
            columnValues[e.NodeID] = (Mode)e.Value;
        }
    }
};
ganttControl1.CustomTaskScheduling += (s, e) => {
    if ((Mode)e.Node.GetValue("ScheduleMode") == Mode.Manual)
        e.Cancel = true;
};
ganttControl1.CustomDrawTask += (s, e) => {
    if ((Mode)e.Node.GetValue("ScheduleMode") == Mode.Manual)
        e.Info.Appearance.BackColor = Color.Green;
};
vb
Imports DevExpress.Utils
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGantt.Options
Imports DevExpress.XtraTreeList.Columns

Private Enum Mode
    Manual
    Auto
End Enum

Dim colScheduleMode As TreeListColumn = ganttControl1.Columns.AddField("ScheduleMode")
colScheduleMode.UnboundDataType = GetType(Object)
colScheduleMode.Visible = True
colScheduleMode.AbsoluteIndex = 0
ganttControl1.TreeListMappings.HierarchyFieldName = "Name"
colScheduleMode.OptionsColumn.AllowSort = False
colScheduleMode.OptionsColumn.AllowMove = False
colScheduleMode.Caption = "Task Mode"
Dim editor As New RepositoryItemImageComboBox()
editor.SmallImages = imageCollection1
editor.Items.Add(New ImageComboBoxItem("Manually Scheduled", Mode.Manual, 1))
editor.Items.Add(New ImageComboBoxItem("Auto Scheduled", Mode.Auto, 0))
editor.GlyphAlignment = HorzAlignment.Center
AddHandler editor.EditValueChanged, Sub(s, e)
    ganttControl1.PostEditor()
End Sub
ganttControl1.RepositoryItems.Add(editor)
colScheduleMode.ColumnEdit = editor
Dim columnValues As New Dictionary(Of Integer, Mode)()
AddHandler ganttControl1.CustomUnboundColumnData, Sub(sender, e)
    If e.Column.FieldName = "ScheduleMode" Then
        If e.IsGetData Then
            If Not columnValues.ContainsKey(e.NodeID) Then
                columnValues(e.NodeID) = If(ganttControl1.OptionsBehavior.ScheduleMode = ScheduleMode.Manual, Mode.Manual, Mode.Auto)
            End If
            e.Value = columnValues(e.NodeID)
        End If
        If e.IsSetData AndAlso e.Value IsNot Nothing Then
            columnValues(e.NodeID) = CType(e.Value, Mode)
        End If
    End If
End Sub
AddHandler ganttControl1.CustomTaskScheduling, Sub(s, e)
    If CType(e.Node.GetValue("ScheduleMode"), Mode) = Mode.Manual Then
        e.Cancel = True
    End If
End Sub
AddHandler ganttControl1.CustomDrawTask, Sub(s, e)
    If CType(e.Node.GetValue("ScheduleMode"), Mode) = Mode.Manual Then
        e.Info.Appearance.BackColor = Color.Green
    End If
End Sub

See Also

ScheduleMode

Interactive Editing

GanttControl Class

GanttControl Members

DevExpress.XtraGantt Namespace