14th April 2015

DevExpress XAF – Scheduler Control Change Event Colours Depending on a Custom Field

DevExpress XAF – Scheduler Control Change Event Colours Depending on a Custom Field

By default when using the Win Scheduler List Editor List Editor Type when viewing your Events using the Scheduler Control, the colour of the Event will depend on the colour set up against your Event Type. It may be required for the colour of the Event within the listing to change depending on a custom field such as an Event Status. The code snippet below examples changing the Event colour depending on the value selected within a custom field against your Event, it needs to be implemented within a View Controller against the Module.Win project.

using System.Drawing;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Scheduler.Win;
using DevExpress.Persistent.Base.General;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
 
/// <summary>
/// Scheduler Calendar View Controller
/// </summary>
public partial class SchedulerCalendarViewController : ObjectViewController<ListView, IRecurrentEvent>

/// <summary> /// Initializes a new instance of the <see cref="SchedulerCalendarViewController"/> class. /// </summary> public SchedulerCalendarViewController()

this.InitializeComponent(); this.RegisterActions(this.components);

/// <summary> /// Called when [view controls created]. /// </summary> protected override void OnViewControlsCreated()

base.OnViewControlsCreated(); SchedulerListEditor listEditor = View.Editor as SchedulerListEditor; if (listEditor != null)

SchedulerControl scheduler = listEditor.SchedulerControl; if (scheduler != null)

scheduler.CustomDrawAppointmentBackground += new CustomDrawObjectEventHandler(this.SchedulerControl_CustomDrawObject);

/// <summary> /// Handles the CustomDrawObject event of the SchedulerControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="CustomDrawObjectEventArgs"/> instance containing the event data.</param> private void SchedulerControl_CustomDrawObject(object sender, CustomDrawObjectEventArgs e)

AppointmentViewInfo aptViewInfo = e.ObjectInfo as AppointmentViewInfo; if (aptViewInfo != null)

MyEvent myEvent = this.ObjectSpace.GetObjectByKey<MyEvent>(aptViewInfo.Appointment.Id); if (myEvent != null)

if (myEvent.MyCustomField == "ValueOne")

Brush fillBrush = e.Cache.GetSolidBrush(System.Drawing.Color.LightBlue); e.Graphics.FillRectangle(fillBrush, e.Bounds); if (aptViewInfo.Selected)

Pen selectedPen = e.Cache.GetPen(System.Drawing.Color.Black); Brush selectedBrush = e.Cache.GetSolidBrush(System.Drawing.Color.LightSlateGray); e.Graphics.FillRectangle(selectedBrush, e.Bounds);

else

Brush fillBrush = e.Cache.GetSolidBrush(System.Drawing.Color.LightGreen); e.Graphics.FillRectangle(fillBrush, e.Bounds); if (aptViewInfo.Selected)

Pen selectedPen = e.Cache.GetPen(System.Drawing.Color.Black); Brush selectedBrush = e.Cache.GetSolidBrush(System.Drawing.Color.LightSlateGray); e.Graphics.FillRectangle(selectedBrush, e.Bounds);

e.Handled = true;

Fill in this quick form and discover your digital future
Choose your interests:

Where to find us

We'd love to welcome you into our office! We're only 20 miles north of Peterborough, conveniently just off the A16.

Carver House
Apex Court, Elsoms Way
Pinchbeck
Lincolnshire
PE11 3UL