Back to Devexpress

RepositoryItemDateEdit.DisableCalendarDate Event

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemdateedit-97f7f26f.md

latest4.6 KB
Original Source

RepositoryItemDateEdit.DisableCalendarDate Event

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

Declaration

csharp
[DXCategory("Events")]
public event DisableCalendarDateEventHandler DisableCalendarDate
vb
<DXCategory("Events")>
Public Event DisableCalendarDate As DisableCalendarDateEventHandler

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.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:

csharp
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;
}
vb
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:

csharp
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;
}
vb
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.

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

Edit Data. Create Cell Editors. Validate User Input

RepositoryItemDateEdit Class

RepositoryItemDateEdit Members

DevExpress.XtraEditors.Repository Namespace