MonthCalendar.SelectionStart Property
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.
Gets or sets the start date of the selected range of dates.
public:
property DateTime SelectionStart { DateTime get(); void set(DateTime value); };
[System.ComponentModel.Browsable(false)]
public DateTime SelectionStart { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionStart : DateTime with get, set
Public Property SelectionStart As DateTime
Property Value
A DateTime indicating the first date in the selection range.
- Attributes
Exceptions
Examples
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.
void ShowAWeeksVacationOneMonthFromToday()
{
DateTime today = this->MonthCalendar1->TodayDate;
DateTime vacationStart = today.AddMonths(1);
DateTime vacationEnd = vacationStart.AddDays(7);
// Select the week using SelectionStart and SelectionEnd.
this->MonthCalendar1->SelectionStart = vacationStart.AddDays(-1);
this->MonthCalendar1->SelectionEnd = vacationEnd.AddDays(-1);
}
// Computes a week one month from today.
private void ShowAWeeksVacationOneMonthFromToday()
{
DateTime today = this.MonthCalendar1.TodayDate;
DateTime vacationStart = today.AddMonths(1);
DateTime vacationEnd = vacationStart.AddDays(7);
// Select the week using SelectionStart and SelectionEnd.
this.MonthCalendar1.SelectionStart = vacationStart.AddDays(-1);
this.MonthCalendar1.SelectionEnd = vacationEnd.AddDays(-1);
}
' Computes a week one month from today.
Private Sub ShowAWeeksVacationOneMonthFromToday()
Dim today As Date = monthCalendar1.TodayDate
Dim vacationStart = today.AddMonths(1)
Dim vacationEnd = vacationStart.AddDays(7)
Me.monthCalendar1.SelectionStart = vacationStart.AddDays(-1)
Me.monthCalendar1.SelectionEnd = vacationEnd.AddDays(-1)
End Sub
Remarks
If you set the value of the SelectionStart property to a date that is later than the current value of the SelectionEnd property, SelectionEnd is automatically set equal to SelectionStart.
If you set a date in SelectionStart that causes the selection to exceed the number of days specified by the MaxSelectionCount property, the value of SelectionEnd is adjusted; SelectionEnd 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.