Category / Section
How to disable or hide the previous and next month dates in WinForms DateTimePicker (DateTimePickerAdv)?
1 min read
Disable or hide the previous and next month dates
By default, the trailing date (previous and next months' dates) is visible in the drop-down calendar of the DateTimePickerAdv. You can hide the trailing dates by setting forecolor of trailing dates to White in the DateCellQueryInfo event. The following code example demonstrates how to hide trailing dates in the drop-down calendar of the DateTimePickerAdv.
C#
this.dateTimePickerAdv1.Calendar.DateCellQueryInfo += new DateCellQueryInfoEventHandler(Calendar_DateCellQueryInfo); /// <summary> /// Event to provide custom formatting for calendar cells. /// </summary> void Calendar_DateCellQueryInfo(object sender, DateCellQueryInfoEventArgs e) { if (e.Style.TextColor == this.dateTimePickerAdv1.CalendarTrailingForeColor) { // Hide the trailing dates e.Style.Enabled = false; e.Style.TextColor = Color.White; } }
VB
AddHandler dateTimePickerAdv1.Calendar.DateCellQueryInfo, AddressOf Calendar_DateCellQueryInfo ''' <summary> '''Event to provide custom formatting for calendar cells. ''' </summary> Private Sub Calendar_DateCellQueryInfo(ByVal sender As Object, ByVal e As DateCellQueryInfoEventArgs) If e.Style.TextColor = Me.dateTimePickerAdv1.CalendarTrailingForeColor Then 'Hide the trailing dates e.Style.Enabled = False e.Style.TextColor = Color.White End If End Sub
Sample:
C#: http://www.syncfusion.com/downloads/support/directtrac/general/ze/CS-1146374136
VB: http://www.syncfusion.com/downloads/support/directtrac/general/ze/VB-1476170831