This documentation is archived and is not being maintained.

MonthCalendar.SelectionEnd Property

Gets or sets the end date of the selected range of dates.

[Visual Basic]
Public Property SelectionEnd As DateTime
[C#]
public DateTime SelectionEnd {get; set;}
[C++]
public: __property DateTime get_SelectionEnd();
public: __property void set_SelectionEnd(DateTime);
[JScript]
public function get SelectionEnd() : DateTime;
public function set SelectionEnd(DateTime);

Property Value

A DateTime indicating the last date in the selection range.

Exceptions

Exception Type Condition
ArgumentException The date value is less than the MinDate value.

-or-

The date value is greater than the MaxDate value.

Remarks

If you set SelectionEnd to a date that is earlier than the current SelectionStart, then 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 seven (the default), then SelectionStart and SelectionEnd can be no more than six days apart.

Example

[Visual Basic, C#] The following code example demonstrates how to use the SelectionStart and SelectionEnd properties. To run the example, paste the following code in a form containing a MonthCalendar control named MonthCalendar1 and call the ShowAWeeksVacationOneMonthFromToday method from the form's constructor or Load method.

[Visual Basic] 
' Computes a week one month from today.
Private Sub ShowAWeeksVacationOneMonthFromToday()
    Dim today As Date = Me.MonthCalendar1.TodayDate
    Dim vacationMonth As Integer = 1
    If (today.Month < 12) Then
        vacationMonth = today.Month + 1
    End If

    ' Select the week using SelectionStart and SelectionEnd.
    Me.MonthCalendar1.SelectionStart = _
        New Date(today.Year, vacationMonth, today.Day - 1)
    Me.MonthCalendar1.SelectionEnd = _
        New Date(today.Year, vacationMonth, today.Day + 6)
End Sub

[C#] 
// Computes a week one month from today.
private void ShowAWeeksVacationOneMonthFromToday()
{
    System.DateTime today = this.MonthCalendar1.TodayDate;
    int vacationMonth = 1;
    if (today.Month < 12)
    {
        vacationMonth = today.Month + 1;
    }

    // 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);
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MonthCalendar Class | MonthCalendar Members | System.Windows.Forms Namespace | SelectionRange | SelectionStart | SetSelectionRange

Show: