MonthCalendar.SetSelectionRange(DateTime, DateTime) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sets the selected dates in a month calendar control to the specified date range.
public:
void SetSelectionRange(DateTime date1, DateTime date2);
public void SetSelectionRange (DateTime date1, DateTime date2);
member this.SetSelectionRange : DateTime * DateTime -> unit
Public Sub SetSelectionRange (date1 As DateTime, date2 As DateTime)
Parameters
- date1
- DateTime
The beginning date of the selection range.
- date2
- DateTime
The end date of the selection range.
Exceptions
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.
Remarks
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.
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 SelectionRange for a MonthCalendar control that has visual styles enabled will result in the selection range not painting correctly on the control.
Applies to
See also
.NET