Back to Devexpress

SchedulerControl.InitAppointmentDisplayText Event

windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-b52a5507.md

latest11.0 KB
Original Source

SchedulerControl.InitAppointmentDisplayText Event

Enables custom text and a description to be displayed within appointments.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public event AppointmentDisplayTextEventHandler InitAppointmentDisplayText
vb
Public Event InitAppointmentDisplayText As AppointmentDisplayTextEventHandler

Event Data

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

PropertyDescription
AppointmentProvides access to the appointment for which the SchedulerControl.InitAppointmentDisplayText event is fired.
DescriptionGets or sets the text that will be displayed as an appointment’s description.
TextGets or sets the text that will be displayed as the appointment’s text (subject and location together).
ViewInfoProvides access to the characteristics of the appointment prepared for display.

Remarks

The InitAppointmentDisplayText event occurs before an appointment is painted when its text and description are initialized. This event lets you display custom text and description within appointments.

The event parameter’s AppointmentEventArgs.Appointment property identifies the appointment being processed. The AppointmentDisplayTextEventArgs.Text and AppointmentDisplayTextEventArgs.Description properties specify the text and description to be displayed within the appointment.

Important

Do not modify appointment properties, and do not add or remove appointments within this event handler. An attempt to do so may result in an unhandled exception. If the UseAsyncMode property is enabled, the InitAppointmentImages event raises in the non-UI thread. In this case, performing thread-safe operations may cause a deadlock.

Scheduler layout calculation is split into several threads to improve the scheduler performance. The InitAppointmentDisplayText event could be raised from a thread other than the thread where the SchedulerControl instance has been created. Accessing the SchedulerControl (SchedulerStorage) instance directly in the InitAppointmentDisplayText event when the SchedulerOptionsBehavior.UseAsyncMode property is true may result in “cross-thread” exceptions.

To avoid the “cross-thread” issues, do not access the SchedulerControl or SchedulerStorage instance in the event handler. In most common scenarios, the SchedulerControl or SchedulerStorage instances are used to obtain the content of the underlying source object. In this situation you have to store all the required information within the current appointment instance so that accessing the source object becomes unnecessary. A recommended solution is mapping the required data field to a custom appointment property, as illustrated in the code example below.

Text information for the InitAppointmentDisplayText event handler is provided by specifying appointment mappings:

View Example

csharp
private void InitAppointments() {
    AppointmentMappingInfo mappings = this.schedulerStorage1.Appointments.Mappings;
    mappings.Start = "StartTime";
    mappings.End = "EndTime";
    mappings.Subject = "Subject";
    mappings.AllDay = "AllDay";
    mappings.Description = "Description";
    mappings.Label = "Label";
    mappings.Location = "Location";
    mappings.RecurrenceInfo = "RecurrenceInfo";
    mappings.ReminderInfo = "ReminderInfo";
    mappings.ResourceId = "OwnerId";
    mappings.Status = "Status";
    mappings.Type = "EventType";            

    schedulerStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("ApptImage1", "Icon1", FieldValueType.Object));
    schedulerStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("ApptImage2", "Icon2", FieldValueType.Object));
    schedulerStorage1.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("ApptAddInfo", "AdditionalInfo", FieldValueType.String));

    GenerateEvents(CustomEventList, 3);
}
vb
Private Sub InitAppointments()
    Dim mappings As AppointmentMappingInfo = Me.schedulerStorage1.Appointments.Mappings
    mappings.Start = "StartTime"
    mappings.End = "EndTime"
    mappings.Subject = "Subject"
    mappings.AllDay = "AllDay"
    mappings.Description = "Description"
    mappings.Label = "Label"
    mappings.Location = "Location"
    mappings.RecurrenceInfo = "RecurrenceInfo"
    mappings.ReminderInfo = "ReminderInfo"
    mappings.ResourceId = "OwnerId"
    mappings.Status = "Status"
    mappings.Type = "EventType"

    schedulerStorage1.Appointments.CustomFieldMappings.Add(New AppointmentCustomFieldMapping("ApptImage1", "Icon1", FieldValueType.Object))
    schedulerStorage1.Appointments.CustomFieldMappings.Add(New AppointmentCustomFieldMapping("ApptImage2", "Icon2", FieldValueType.Object))
    schedulerStorage1.Appointments.CustomFieldMappings.Add(New AppointmentCustomFieldMapping("ApptAddInfo", "AdditionalInfo", FieldValueType.String))

    GenerateEvents(CustomEventList, 3)
End Sub

An appointment custom field is used to retrieve the text information within the event handler:

View Example

csharp
private void schedulerControl1_InitAppointmentDisplayText(object sender, AppointmentDisplayTextEventArgs e) {
    // Display custom text in Day and WorkWeek views only (VerticalAppointmentViewInfo).
    if (e.ViewInfo is VerticalAppointmentViewInfo && e.Appointment.CustomFields["ApptAddInfo"] != null) {
        e.Text = e.Appointment.Subject + "\r\n";
        e.Text += "------\r\n";
        e.Text += e.Appointment.CustomFields["ApptAddInfo"].ToString();
    }
}
vb
Private Sub schedulerControl1_InitAppointmentDisplayText(ByVal sender As Object, ByVal e As AppointmentDisplayTextEventArgs)
    ' Display custom text in Day and WorkWeek views only (VerticalAppointmentViewInfo).
    If TypeOf e.ViewInfo Is VerticalAppointmentViewInfo AndAlso e.Appointment.CustomFields("ApptAddInfo") IsNot Nothing Then
        e.Text = e.Appointment.Subject & ControlChars.CrLf
        e.Text &= "------" & ControlChars.CrLf
        e.Text += e.Appointment.CustomFields("ApptAddInfo").ToString()
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the InitAppointmentDisplayText 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.

xaf-how-to-display-an-event-with-custom-fields-in-a-scheduler-list-view/CS/EFCore/ExtendedEvents.Win/Controllers/SchedulerCustomFieldMappingsController.cs#L19

csharp
SchedulerControl scheduler = listEditor.SchedulerControl;
scheduler.InitAppointmentDisplayText -= scheduler_InitAppointmentDisplayText;
scheduler.InitAppointmentDisplayText += scheduler_InitAppointmentDisplayText;

how-to-initialize-appointment-images-and-display-text-using-the-custom-field-values-t328320/CS/CustomAppointmentImageAndText/Form1.cs#L19

csharp
//this.schedulerStorage1.Resources.ColorSaving = ColorSavingType.Color;
schedulerControl1.InitAppointmentDisplayText += schedulerControl1_InitAppointmentDisplayText;
schedulerControl1.InitAppointmentImages += schedulerControl1_InitAppointmentImages;

how-to-initialize-appointment-images-and-display-text-using-the-custom-field-values-t328320/VB/CustomAppointmentImageAndText/Form1.vb#L19

vb
'this.schedulerStorage1.Resources.ColorSaving = ColorSavingType.Color;
AddHandler schedulerControl1.InitAppointmentDisplayText, AddressOf schedulerControl1_InitAppointmentDisplayText
AddHandler schedulerControl1.InitAppointmentImages, AddressOf schedulerControl1_InitAppointmentImages

See Also

InitAppointmentImages

SchedulerControl Class

SchedulerControl Members

DevExpress.XtraScheduler Namespace