How to: Filter Appointments

  • 2 minutes to read

FilterAppointment event

The following example demonstrates how to filter the appointments shown within a Scheduler Control according to some condition. For this the SchedulerDataStorage.FilterAppointment event is used. The code below demonstrates how to hide all tentative appointments (those whose status is set to AppointmentStatusType.Tentative).

using DevExpress.XtraScheduler;
// ...

private void schedulerDataStorage1_FilterAppointment(object sender, PersistentObjectCancelEventArgs e) {
   // Filter all tentative appointments.
   e.Cancel = ((Appointment)e.Object).StatusId == 1;

Filter Control

You can use the FilterControl to provide the end-user with a flexible tool to build complex filter criteria.

Suppose your appointment has a custom field CustomFieldPrice, mapped as follows:

using DevExpress.XtraScheduler;

AppointmentCustomFieldMapping customPriceMapping = 
    new AppointmentCustomFieldMapping("CustomFieldPrice", "Price", FieldValueType.Decimal);

Place the FilterControl onto the form. Name it filterControlForAppointments. Specify the SchedulerStorage.Appointments storage as the source control of the FilterControl using the FilterControl.SourceControl property.

At runtime, you'll be able to construct a complex criterion, as illustrated in the following picture:


The filter string, obtained via the FilterControl.FilterString property, looks as follows:

[AllDay] = True And [Subject] Like 'R%' And [Description] Like '%Check%' And [Start] Between(#2009-12-13#, #2009-12-25#) And [CustomFieldPrice] >= 10.00m Or [Status] = 3 And [Label] = 7

This filter leaves the Scheduler appointments with Status equal to 'Out Of Office' labeled 'Need Preparation', and also, all-day appointments which start between 13 and 25 December, 2009, having a subject starting with 'R', containing string "Check" in the description, and priced equal to or higher than 10.

To apply this criterion to the scheduler appointment storage, use this code:

schedulerControl.Storage.Appointments.Filter = filterControlForAppointments.FilterString;