Skip to main content
All docs
V24.1

How to: Adjust Automatic Scheduling

  • 2 minutes to read

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.

image

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