Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

RepositoryItemDateEdit.DisableCalendarDate Event

Allows you to disable dates or date ranges in a DateEdit dropdown.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.2.dll

NuGet Package: DevExpress.Win.Navigation

#Declaration

[DXCategory("Events")]
public event DisableCalendarDateEventHandler DisableCalendarDate

#Event Data

The DisableCalendarDate event's data class is DevExpress.XtraEditors.Calendar.DisableCalendarDateEventArgs.

#Remarks

The DisableCalendarDate event allows you to disable specific calendar dates in a DateEdit dropdown. A user cannot select disabled dates.

The DisableCalendarDate event fires when a DateEdit’s dropdown is about to be displayed.

The following event parameters determine the processed date:

e.DateOnly
Supplies information about the processed date.
e.DateTime
Supplies information about the processed date or time.

Set the e.IsDisabled parameter to true to disable a date.

The following code snippet disables the 16th day of every month in an in-place DateEdit:

using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Calendar;
void Dates_DisableCalendarDate(object sender, DisableCalendarDateEventArgs e) {
     if (e.View != DateEditCalendarViewType.MonthInfo) return;
     if (e.DateOnly.Day == 16)
          e.IsDisabled = true;
}

The following screenshot shows the result:

DevExpress WinForms DateEdit disable calendar dates

The following code snippet disables weekends in a standalone DateEdit:

using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Calendar;
void dateEdit1_DisableCalendarDate(object sender, DisableCalendarDateEventArgs e) {
     if (e.View != DateEditCalendarViewType.MonthInfo) return;
     if (e.DateOnly.DayOfWeek == DayOfWeek.Saturday || e.DateOnly.DayOfWeek == DayOfWeek.Sunday)
          e.IsDisabled = true;
}

The following screenshot shows the result:

DevExpress WinForms DateEdit disable calendar dates

Tip

Use the RepositoryItemDateEdit.AppearanceCalendar property to specify custom appearance settings for disabled dates.

#Handle Disabled Dates

If a user enters a disabled date in the edit box and tries to move cell focus, an error occurs, and the user cannot leave the cell until they modify the value.

To implement a custom error response, do the following:

  • In a standalone DateEdit, handle the InvalidValue event.
  • In a container control, handle the container control’s InvalidValueException event.
See Also