This documentation is archived and is not being maintained.

MonthCalendar.SelectionRange Property

Gets or sets the selected range of dates for a month calendar control.

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

[BindableAttribute(true)]
public SelectionRange SelectionRange { get; set; }

Property Value

Type: System.Windows.Forms.SelectionRange
A SelectionRange with the start and end dates of the selected range.

ExceptionCondition
ArgumentOutOfRangeException

The Start value of the assigned SelectionRange is less than the minimum date allowable for a month calendar control.

-or-

The Start value of the assigned SelectionRange is greater than the maximum allowable date for a month calendar control.

-or-

The End value of the assigned SelectionRange is less than the minimum date allowable for a month calendar control.

-or-

The End value of the assigned SelectionRange is greater than the maximum allowable date for a month calendar control.

Setting this property is functionally equivalent to using the SetSelectionRange method. You can set the start and end dates separately by setting either the SelectionStart or SelectionEnd properties. You cannot change the start and end dates by setting the SelectionRange.Start or SelectionRange.End property values of the SelectionRange property. You should use SelectionStart, SelectionEnd, or SetSelectionRange.

If the Start property value of the SelectionRange is greater than its End property value, the dates are swapped; the End property value becomes the starting date, and Start property value becomes the end date.

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 to March 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.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: