Back to Devexpress

GanttControl.CustomTimelineItemText Event

windowsforms-devexpress-dot-xtragantt-dot-ganttcontrol-7e8d2d76.md

latest7.9 KB
Original Source

GanttControl.CustomTimelineItemText Event

Allows you to specify a custom caption and details for tasks displayed on the timeline.

Namespace : DevExpress.XtraGantt

Assembly : DevExpress.XtraGantt.v25.2.dll

NuGet Package : DevExpress.Win.Gantt

Declaration

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

Event Data

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

PropertyDescription
CaptionGets or sets the task caption (in the timeline).
DetailsGets or sets the task details (in the timeline).
NodeGets the node that corresponds to the task displayed on the timeline.
TaskGets the view information about the task (on the timeline).

Remarks

The Gantt control fires the CustomTimelineItemText event for each task displayed on the timeline and allows you to change its caption and details based on a condition. Use the e.Caption and e.Details properties to specify the caption and details of a task. The e.Task property returns the task.

The following example demonstrates how to specify a custom caption and description for tasks displayed on a timeline based on a condition:

csharp
public Form1() {
    InitializeComponent();
    // Bind the Gantt control to a data source.
    ganttControl1.DataSource = TaskData.InitData();
    // Configures the Gantt control's mappings.
    ganttControl1.TreeListMappings.KeyFieldName = "Id";
    ganttControl1.TreeListMappings.ParentFieldName = "ParentId";
    ganttControl1.ChartMappings.StartDateFieldName = "StartDate";
    ganttControl1.ChartMappings.FinishDateFieldName = "EndDate";
    ganttControl1.ChartMappings.TimelineCaption = "Name";
    // Maps the Gantt control to a field in a data source with Boolean values that
    // specify which tasks to display on the timeline when the application starts.
    ganttControl1.ChartMappings.VisibleInTimelineFieldName = "ShowInTimeline";
    // Displays the timeline at the top of the Gantt control.
    ganttControl1.OptionsTimeline.TimelinePosition = DevExpress.XtraGantt.TimelinePosition.Top;
    ganttControl1.CustomTimelineItemText += GanttControl1_CustomTimelineItemText;
}
private void GanttControl1_CustomTimelineItemText(object sender, DevExpress.XtraGantt.CustomItemTextEventArgs e) {
    // Displays a common caption if no task caption is specified.
    e.Caption = string.IsNullOrEmpty(e.Caption) ? "Noname Task" : string.Format("Task: {0}", e.Caption);
    // Displays a value from the Description data field in the task details (if specified).
    string customDetails = (string)e.Node["Description"];
    e.Details = !string.IsNullOrEmpty(customDetails) ? customDetails : e.Details;
}
public class TaskData {
    public TaskData(int id) {
        this.id = id;
    }
    int id;
    public int Id {
        get { return id; }
    }
    public bool ShowInTimeline { get; set; } = false;
    public int ParentId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public static List<TaskData> InitData() {
        return new List<TaskData>() {
            new TaskData(0){ Name = "Task A", ParentId = 0, StartDate = new DateTime(2023, 3, 1), EndDate = new DateTime(2024, 3, 31) },
            new TaskData(1){
                Name = "Task B",
                ParentId = 0,
                StartDate = new DateTime(2023, 3, 1),
                EndDate = new DateTime(2023, 7, 1),
                ShowInTimeline = true,
                Description = "The description of Task B." },
            new TaskData(2){ ParentId = 0, StartDate = new DateTime(2023, 7, 1), EndDate = new DateTime(2023, 11, 1) }
        };
    }
}
vb
Public Sub New()
    InitializeComponent()
    ' Bind the Gantt control to a data source.
    ganttControl1.DataSource = TaskData.InitData()
    ' Configures the Gantt control's mappings.
    ganttControl1.TreeListMappings.KeyFieldName = "Id"
    ganttControl1.TreeListMappings.ParentFieldName = "ParentId"
    ganttControl1.ChartMappings.StartDateFieldName = "StartDate"
    ganttControl1.ChartMappings.FinishDateFieldName = "EndDate"
    ganttControl1.ChartMappings.TimelineCaption = "Name"
    ' Maps the Gantt control to a field in a data source with Boolean values that
    ' specify which tasks to display on the timeline when the application starts.
    ganttControl1.ChartMappings.VisibleInTimelineFieldName = "ShowInTimeline"
    ' Displays the timeline at the top of the Gantt control.
    ganttControl1.OptionsTimeline.TimelinePosition = DevExpress.XtraGantt.TimelinePosition.Top
    AddHandler ganttControl1.CustomTimelineItemText, AddressOf GanttControl1_CustomTimelineItemText
End Sub
Private Sub GanttControl1_CustomTimelineItemText(ByVal sender As Object, ByVal e As DevExpress.XtraGantt.CustomItemTextEventArgs)
    ' Displays a common caption if no task caption is specified.
    e.Caption = If(String.IsNullOrEmpty(e.Caption), "Noname Task", String.Format("Task: {0}", e.Caption))
    ' Displays a value from the Description data field in the task details (if specified).
    Dim customDetails As String = CStr(e.Node("Description"))
    e.Details = If((Not String.IsNullOrEmpty(customDetails)), customDetails, e.Details)
End Sub
Public Class TaskData
    Public Sub New(ByVal id As Integer)
        Me.id_Renamed = id
    End Sub
    Private id_Renamed As Integer
    Public ReadOnly Property Id() As Integer
        Get
            Return id_Renamed
        End Get
    End Property
    Public Property ShowInTimeline() As Boolean
    = False
    public Integer ParentId {get;set;}
    public String Name {get;set;}
    public String Description {get;set;}
    public DateTime StartDate {get;set;}
    public DateTime EndDate {get;set;}
    public static List(Of TaskData) InitData()
        Return New List(Of TaskData)() From {
            New TaskData(0) With {.Name = "Task A", .ParentId = 0, .StartDate = New Date(2023, 3, 1), .EndDate = New Date(2024, 3, 31)},
            New TaskData(1) With {.Name = "Task B", .ParentId = 0, .StartDate = New Date(2023, 3, 1), .EndDate = New Date(2023, 7, 1), .ShowInTimeline = True, .Description = "The description of Task B."},
            New TaskData(2) With {.ParentId = 0, .StartDate = New Date(2023, 7, 1), .EndDate = New Date(2023, 11, 1)}
        }
End Class

See Also

TimelineCaption

GanttControl Class

GanttControl Members

DevExpress.XtraGantt Namespace