Skip to main content

RepositoryItemDateEdit.DisableCalendarDate Event

Allows specific dates or date ranges to be disabled in the editor’s drop-down to prevent them from being selected by an end-user.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v23.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 dates/date ranges in the editor’s drop-down. Disabled dates cannot be selected by an end-user in the editor’s drop-down or by typing them in the edit box. Disabled dates are painted with a strikethrough. You can provide custom appearance settings used to paint disabled dates in the dropdown via the RepositoryItemDateEdit.AppearanceCalendar property.

If a disabled date is entered in the edit box and focus is about to be moved away to another control, an error occurs, which is indicated by an error icon. You can respond to this error by handling the BaseEdit.InvalidValue event. In container controls (e.g., GridControl and TreeList), handle the InvalidValueException event provided by these controls (e.g., BaseView.InvalidValueException and TreeList.InvalidValueException).

When handling the DisableCalendarDate event, read the DisableCalendarDateEventArgs.Date property to determine the currently processed date and set the DisableCalendarDateEventArgs.IsDisabled property to true for those that should be disabled.

The following code illustrates how to disable weekends in the calendar.

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