windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemdateedit-97f7f26f.md
Allows you to disable dates or date ranges in a DateEdit dropdown.
Namespace : DevExpress.XtraEditors.Repository
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event DisableCalendarDateEventHandler DisableCalendarDate
<DXCategory("Events")>
Public Event DisableCalendarDate As DisableCalendarDateEventHandler
The DisableCalendarDate event's data class is DevExpress.XtraEditors.Calendar.DisableCalendarDateEventArgs.
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.DateOnlySupplies information about the processed date.e.DateTimeSupplies 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;
}
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Calendar
Private Sub Dates_DisableCalendarDate(ByVal sender As Object, ByVal e As DisableCalendarDateEventArgs)
If e.View <> DateEditCalendarViewType.MonthInfo Then
Return
End If
If e.DateOnly.Day = 16 Then
e.IsDisabled = True
End If
End Sub
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;
}
Imports DevExpress.XtraEditors.Controls
Imports DevExpress.XtraEditors.Calendar
Private Sub dateEdit1_DisableCalendarDate(ByVal sender As Object, ByVal e As DisableCalendarDateEventArgs)
If e.View <> DateEditCalendarViewType.MonthInfo Then
Return
End If
If e.DateOnly.DayOfWeek = DayOfWeek.Saturday OrElse e.DateOnly.DayOfWeek = DayOfWeek.Sunday Then
e.IsDisabled = True
End If
End Sub
The following screenshot shows the result:
Tip
Use the RepositoryItemDateEdit.AppearanceCalendar property to specify custom appearance settings for 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:
InvalidValueException event.See Also
Edit Data. Create Cell Editors. Validate User Input