This documentation is archived and is not being maintained.

Selecting a Range of Dates in the Windows Forms MonthCalendar Control

Visual Studio .NET 2003

A key feature of the Windows Forms MonthCalendar control is that the user can select a range of dates, unlike the similar DateTimePicker control, which only allows a single date/time value to be selected.

To select a range of dates

  1. Create the DateTime objects that represent the first and last dates in the range.
    ' Visual Basic
    Dim projectStart As Date = New DateTime(2001, 2, 13)
    Dim projectEnd As Date = New DateTime(2001, 2, 28)
    
    // C#
    DateTime projectStart = new DateTime(2001, 2, 13);
    DateTime projectEnd = new DateTime(2001, 2, 28);
    
    // C++
    DateTime projectStart = DateTime(2001, 2, 13);
    DateTime projectEnd = DateTime(2001, 2, 28);
    
  2. Set the SelectionRange property.
    ' Visual Basic
    MonthCalendar1.SelectionRange = New SelectionRange(projectStart, projectEnd)
    
    // C#
    monthCalendar1.SelectionRange = new SelectionRange(projectStart, projectEnd);
    
    // C++
    monthCalendar1->SelectionRange = new
       SelectionRange(projectStart, projectEnd);
    

    – Or –

    Set the SelectionStart and SelectionEnd properties.

    ' Visual Basic
    MonthCalendar1.SelectionStart = projectStart
    MonthCalendar1.SelectionEnd = projectEnd
    
    // C#
    monthCalendar1.SelectionStart = projectStart;
    monthCalendar1.SelectionEnd = projectEnd;
    
    // C++
    monthCalendar1->SelectionStart = projectStart;
    monthCalendar1->SelectionEnd = projectEnd;
    

See Also

MonthCalendar Control (Windows Forms) | Changing the Windows Forms MonthCalendar Control's Appearance | Displaying Specific Days in Bold with the Windows Forms MonthCalendar Control | Displaying More than One Month in the Windows Forms MonthCalendar Control | Introduction to the Windows Forms DateTimePicker Control

Show: