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
#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:
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:
Tip
Use the Repository
#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.