Back to Devexpress

GanttControl.CustomTaskDisplayText Event

windowsforms-devexpress-dot-xtragantt-dot-ganttcontrol-88a81f9c.md

latest7.0 KB
Original Source

GanttControl.CustomTaskDisplayText Event

Allows you to specify the caption displayed inside, to the left, and to the right of a task.

Namespace : DevExpress.XtraGantt

Assembly : DevExpress.XtraGantt.v25.2.dll

NuGet Package : DevExpress.Win.Gantt

Declaration

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

Event Data

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

PropertyDescription
InsideTextGets or sets the text displayed inside the task’s bar. This property is not in effect for summary tasks and milestones.
LeftTextGets or sets the text displayed to the left of the task’s bar.
NodeGets the processed node.
RightTextGets or sets the text displayed to the right of the task’s bar.
TaskInfoProvides access to view information about the task.

Remarks

The GanttControl.ChartMappings property provides access to data fields mapped to task properties that specify how a task is displayed in the chart area. The TextFieldName property specifies the data field that contains task captions.

The caption is displayed next to the task in the chart area. To obtain a task’s caption in code, you can use the GetText(GanttControlNode), GetText(Int32), and GetText() methods.

You can also handle the CustomTaskDisplayText event, which fires before a task is displayed, to specify a caption dynamically.

A task’s caption can also be displayed in interaction tooltips. You can use the InteractionTooltipTextFieldName property to specify the data field that contains task captions for tooltips. To obtain a task’s tooltip caption in code, use the GetTooltipText(Int32) method.

Example

The code below shows how to display captions to the left and to the right of the bars.

csharp
HashSet<int> criticalPathIds = new HashSet<int> { 1, 2, 3, 6, 7, 8, 10, 11, 13 };
ganttControl.CustomTaskDisplayText += (sender, e) => {
    int taskId = Convert.ToInt32(e.Node.GetValue("Id"));
    if(criticalPathIds.Contains(taskId)) {
        e.RightText = "High priority";
    }
    else {
        e.RightText = string.Empty;
        e.LeftText = "Normal priority";
    }
};
vb
Dim criticalPathIds As New HashSet(Of Integer)() From {1, 2, 3, 6, 7, 8, 10, 11, 13}
AddHandler ganttControl.CustomTaskDisplayText, Sub(sender, e)
    Dim taskId As Integer = Convert.ToInt32(e.Node.GetValue("Id"))
    If criticalPathIds.Contains(taskId) Then
        e.RightText = "High priority"
    Else
        e.RightText = String.Empty
        e.LeftText = "Normal priority"
    End If
End Sub

Note

Run the Gantt Code Examples demo to see the complete example.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomTaskDisplayText event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-dashboard-custom-items-extension/CS/CustomItemExtension/CustomItems/GanttItem/GanttItemControlProvider.cs#L38

csharp
gantt.CustomPrintTask += Gantt_CustomPrintTask;
gantt.CustomTaskDisplayText += Gantt_CustomTaskDisplayText;
gantt.CustomColumnDisplayText += Gantt_CustomColumnDisplayText;

winforms-dashboard-custom-items-extension/VB/CustomItemExtension/CustomItems/GanttItem/GanttItemControlProvider.vb#L35

vb
AddHandler gantt.CustomPrintTask, AddressOf Gantt_CustomPrintTask
AddHandler gantt.CustomTaskDisplayText, AddressOf Gantt_CustomTaskDisplayText
AddHandler gantt.CustomColumnDisplayText, AddressOf Gantt_CustomColumnDisplayText

See Also

Tasks, Summaries, and Milestones

Obtaining and Setting Cell Values

GetText(GanttControlNode)

GetText(Int32)

GetName(GanttControlNode)

GetText()

TextFieldName

InteractionTooltipTextFieldName

GanttControl Class

GanttControl Members

DevExpress.XtraGantt Namespace