Skip to main content
A newer version of this page is available. .

WorkDaysCollection Class

Represents a collection of dates, for which the information regarding a working activity is known.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v19.1.Core.dll

Declaration

public class WorkDaysCollection :
    NotificationCollection<WorkDay>,
    ICloneable

The following members return WorkDaysCollection objects:

Library Related API Members
Cross-Platform Class Library SchedulerPrintAdapter.GetWorkDays()
WorkDaysCollection.Clone()
WinForms Controls SchedulerControl.WorkDays
SchedulerControlPrintAdapter.GetWorkDays()
WPF Controls SchedulerControl.WorkDays
ASP.NET Web Forms Controls ASPxScheduler.WorkDays
ASPxSchedulerStorageControl.WorkDays
SchedulerSettings.WorkDays
SchedulerStorageControlSettings.WorkDays

Remarks

Populate the WorkDaysCollection collection with objects of WeekDaysWorkDay, Holiday and ExactWorkDay to feed the scheduler with information on work days and holidays. Use the WorkDaysCollection.IsWorkDay method to determine whether the specified date is a work day or a holiday.

Example

The following example demonstrates how to add custom holidays to your scheduling application. For this you need to create a Holiday object for every custom holiday, and add it to the SchedulerControl.WorkDays collection.

The code below demonstrates how to define a collection of custom holidays in the USA for 2007, and how to add them to the Scheduler Control.


using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
// ...

    // A collection of US Holidays for 2007.
    private Holiday[] USHolidays2007 = { 
        new Holiday(new DateTime(2007, 1, 1), "New Year's Day"),
        new Holiday(new DateTime(2007, 1, 15), "Martin Luther King Jr.'s Birthday"),
        new Holiday(new DateTime(2007, 2, 19), "Presidents' Day"),
        new Holiday(new DateTime(2007, 4, 6), "Good Friday"),
        new Holiday(new DateTime(2007, 5, 28), "Memorial Day"),
        new Holiday(new DateTime(2007, 7, 4), "Independence Day"),
        new Holiday(new DateTime(2007, 9, 3), "Labor Day"),
        new Holiday(new DateTime(2007, 11, 22), "Thanksgiving Day"),
        new Holiday(new DateTime(2007, 12, 25), "Christmas Day")
    };

    // This method adds all US Holidays from the USHolidays2007 collection
    // to the WorkDays collection of the Scheduler Control.
    private void GenerateHolidaysFor2007() {
        foreach (Holiday item in USHolidays2007) {
            this.schedulerControl1.WorkDays.Add(item);
        }
    }

For example, these holidays may be added when a form containing a Scheduler Control is loaded.


private void Form1_Load(object sender, EventArgs e) {
        GenerateHolidaysFor2007();
    }

When a holiday is added to the SchedulerControl.WorkDays collection, the Date Navigator shows these holidays in Red (if its DateNavigator.HighlightHolidays property is set to true). In addition, it may be required to mark holidays when they are displayed within a Scheduler Control. For example, you may handle the SchedulerControl.CustomDrawDayHeader event, and add the holiday’s name to the header’s caption, as shown in the code below.

private void schedulerControl1_CustomDrawDayHeader(object sender, 
CustomDrawObjectEventArgs e) {
    // Check whether the current object is a Day Header.
    SchedulerHeader header = e.ObjectInfo as SchedulerHeader;
    if (header != null) {

        // Check whether the current date is a known holiday.
        Holiday hol = FindHoliday(header.Interval.Start.Date);
        if (hol != null) {

            // Add the holiday name to the day header's caption.
            header.Caption = String.Format("{0} ({1})", hol.DisplayName, 
                hol.Date.ToShortDateString());
        }
    }
}

// This method finds a holiday for the specified date.
private Holiday FindHoliday(DateTime date) {
    foreach (WorkDay item in schedulerControl1.WorkDays) {
        if (item is Holiday) {
            Holiday hol = (Holiday)item;
            if (hol.Date == date)
                return hol;
        }
    }
    return null;
}
See Also