System.Windows.Forms.MonthCalendar.SetSelectionRange Method

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

Syntax

public void SetSelectionRange (DateTime date1, DateTime date2)

Parameters

date1
The beginning date of the selection range.
date2
The end date of the selection range.

Remarks

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

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

Note:

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.

Note:

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

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0