MonthCalendar.SelectionEnd Property
Gets or sets the end date of the selected range of dates.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException |
The date value is less than the MinDate value. -or- The date value is greater than the MaxDate value. |
If you set the value of the SelectionEnd property to a date that is earlier than the current value of the SelectionStart property, SelectionStart is automatically set equal to SelectionEnd.
If you set a date in SelectionEnd that causes the selection to exceed the number of days specified by the MaxSelectionCount property, the value of SelectionStart is adjusted; SelectionStart is automatically set so that the number of days selected is equal to MaxSelectionCount.
Note
|
|---|
|
MaxSelectionCount represents the number of days in the selection, not the difference between SelectionStart and SelectionEnd. For example, if MaxSelectionCount is 7 (the default), then SelectionStart and SelectionEnd can be no more than six days apart. |
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. |
The following code example demonstrates how to use the SelectionStart and SelectionEnd properties. To run the example, paste the following code into a form containing a MonthCalendar control named MonthCalendar1, and call the ShowAWeeksVacationOneMonthFromToday method from the form's constructor or Load event-handling method.
// Computes a week one month from today. private void ShowAWeeksVacationOneMonthFromToday() { System.DateTime today = this.MonthCalendar1.TodayDate; int vacationMonth = today.Month + 1; int vacationYear = today.Year; if (today.Month == 12) { vacationMonth = 1; ++vacationYear; } // Select the week using SelectionStart and SelectionEnd. this.MonthCalendar1.SelectionStart = new System.DateTime(today.Year, vacationMonth, today.Day-1); this.MonthCalendar1.SelectionEnd = new System.DateTime(today.Year, vacationMonth, today.Day+6); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note