Datetimepicker problmes

ss002d6252

New member
Joined
Jul 3, 2006
Messages
4
Programming Experience
Beginner
I have a list box on my form with 2 value - "2010" & "2011"

When I change the value in the listbox it should set the minimum and maximum value of 2 datetimepickers.

Each time I try to change the value I get an error - for example if I change the listbox from 2011 to 2010 I get the error:
"Value of '31/03/2011 00:00:00' is not valid for 'MaxDate'. 'MaxDate' must be greater than or equal to MinDate.
Parameter name: MaxDate"

Any help would be appreciated (I'm back to using vb.net after a couple of years off so I'm a bit rusty to say the least).

VB.NET:
          If ListBox1.SelectedIndex = "0" Then
            DateTimePicker1.MaxDate = #3/31/2011#
            DateTimePicker1.MinDate = #4/1/2010#
            DateTimePicker2.MaxDate = #3/31/2011#
            DateTimePicker2.MinDate = #4/1/2010#
        End If


        If ListBox1.SelectedIndex = "1" Then
            DateTimePicker1.MaxDate = #3/31/2012#
            DateTimePicker1.MinDate = #4/1/2011#
            DateTimePicker2.MaxDate = #3/31/2012#
            DateTimePicker2.MinDate = #4/1/2011#
        End If
 
You're setting the properties in the wrong order. For instance, if the MinDate and MaxDate are currently #1/01/2000# and #12/31/2000# and you want to increase the year from 2000 to 2001, you can't set the MinDate first because that would mean that it would have to be higher than MaxDate. To increase the year you would have to set MaxDate first and then MinDate. Likewise, if you are decreasing the year, you must set MinDate before MaxDate.
 
Back
Top