SelectionRange Constructor (DateTime, DateTime)

 

Initializes a new instance of the SelectionRange class with the specified beginning and ending dates.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public SelectionRange(
	DateTime lower,
	DateTime upper
)

Parameters

lower
Type: System.DateTime

The starting date in the SelectionRange.

upper
Type: System.DateTime

The ending date in the SelectionRange.

System_CAPS_noteNote

If the lowerDateTime value is greater than the upperDateTime value, the lower value will be assigned to the End property instead of the Start property.

The following example sets the SelectionRange property of a MonthCalendar control based on two dates entered into two TextBox controls when a Button is clicked. This code assumes new instances of a MonthCalendar control, two TextBox controls, and a Button have been created on a Form. You might consider adding code to validate the Text assigned to the text boxes to verify that they contain valid dates.

private void button1_Click(object sender,
                           EventArgs e)
{
   // Set the SelectionRange with start and end dates from text boxes.
   try
   {
      monthCalendar1.SelectionRange = new SelectionRange(
        DateTime.Parse(textBox1.Text),
        DateTime.Parse(textBox2.Text));
   }
   catch(Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}

.NET Framework
Available since 1.1
Return to top
Show: