DateTimePicker Problems

G

Guest

If have a problem in VB.NET 2003 with the DateTimePicker. If I place the
control on a form and run my application I get an error as the form opens
saying:

An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: '01/01/0001 00:00:00' is not a valid value for
'Value'. 'Value' should be between 'MinDate' and 'MaxDate'.


When I check my code I find the following default setting for the datepicker

Me.dtEndDate.BackColorReadOnly = System.Drawing.SystemColors.Info
Me.dtEndDate.Checked = False
Me.dtEndDate.CustomFormat = Nothing
Me.dtEndDate.DateFormat = System.Windows.Forms.DateTimePickerFormat.Short
Me.dtEndDate.Location = New System.Drawing.Point(116, 144)
Me.dtEndDate.Name = "dtEndDate"
Me.dtEndDate.ReadOnlyValue = False
Me.dtEndDate.ShowCheckBox = True
Me.dtEndDate.Size = New System.Drawing.Size(104, 24)
Me.dtEndDate.TabIndex = 3
Me.dtEndDate.Value = New Date(CType(0, Long))


If I change the value assigned to the .Value property then the application
will run, however as soon as I change anything on the form in the designer
the IDE re-adjusts the value back to the above (New Date(CType(0, Long))) and
the application form crashes again.

Has anyone else experienced this and does anyone have any ideas for a
solution?
 
G

Guest

In the IDE, make sure the date assigned to .Value is really between the
MinDate and MaxDate properties.

In code, if you don't care about the value being valid, catch and ignore the
error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top