MonthCalendar.SetSelectionRange Method

Sets the selected dates in a month calendar control to the specified date range.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void SetSelectionRange(
	DateTime date1,
	DateTime date2
)

Parameters

date1
Type: System.DateTime

The beginning date of the selection range.

date2
Type: System.DateTime

The end date of the selection range.

ExceptionCondition
ArgumentOutOfRangeException

date1 is less than the minimum date allowable for a month calendar control.

-or-

date1 is greater than the maximum allowable date for a month calendar control.

-or-

date2 is less than the minimum date allowable for a month calendar control.

-or-

date2 is greater than the maximum allowable date for a month calendar control.

This exception will only be thrown if MinDate or MaxDate have been set explicitly.

Using this method is functionally equivalent to setting the SelectionRange property. You can set the start and end dates separately by setting either the SelectionStart or SelectionEnd property.

If you set the date1 parameter greater than the date2 parameter, both dates are set to the date1 value.

NoteNote

Scrolling through the calendar display with the navigation buttons when a range is selected can cause unexpected results (for example, the date range is not preserved). If you have a single month displayed with a range of 04/01/2001 to 04/10/2001, scrolling the calendar back changes the selected range as follows: 03/01/2001 to 03/10/2001. If you have multiple months displayed, such as March and April with a selected range of 04/01/2001 to 04/10/2001, scrolling the calendar back to January and February changes the selected range as follows: 01/01/2001 to 01/10/2001.

NoteNote

Setting the SelectionRange for a MonthCalendar control that has visual styles enabled will result in the selection range not painting correctly on the control.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft