Home All Groups Group Topic Archive Search About

How to set the default value of a date picker to nothing (blank)

Author
5 Apr 2005 12:17 PM
Eduardo78
I need to have a control where the default value equals nothing, and if an
user enters a value It validates that it is a date, if not show an error
message or advertise that only dates are allowed.


thanks for any suggestion.

Author
5 Apr 2005 12:51 PM
Cor Ligthert
Eduardo,

You mean a textbox with this (code partially from MSDN)
\\\\\
Private Sub nameTextBox1_Validated(sender As Object, e As System.EventArgs)
Handles nameTextBox1.Validated
            If IsDate(TextBox1.Text) Then
                ' Clear the error, if any, in the error provider.
                dateErrorProvider.SetError(TextBox1, "")
            Else
                ' Set the error if the name is not valid.
                dateErrorProvider.SetError(TextBox1, "Date is wrong")
            End If
End Sub
////

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformserrorproviderclasstopic.asp

I hope this helps,

Cor
Author
5 Apr 2005 1:26 PM
Oenone
Eduardo78 wrote:
> I need to have a control where the default value equals nothing, and
> if an user enters a value It validates that it is a date, if not show
> an error message or advertise that only dates are allowed.

I don't believe it is possible to do this with the DateTimePicker -- it
always displays a date.

--

(O) e n o n e
Author
5 Apr 2005 4:00 PM
Herfried K. Wagner [MVP]
"Eduardo78" <Eduard***@discussions.microsoft.com> schrieb:
>I need to have a control where the default value equals nothing, and if an
> user enters a value It validates that it is a date, if not show an error
> message or advertise that only dates are allowed.

You may want to set the 'ShowCheckBox' property to 'True' and use the
checkbox as a null value indicator (if 'Checked' is 'False', no date is
selected).  Notice that the 'ShowCheckBox' property is flawed and thus this
is not the best way.

Nullable DateTimePicker
<URL:http://www.codeproject.com/cs/miscctrl/Nullable_DateTimePicker.asp>

(For a translation to VB.NET, take a look at the comments section of the
page.)

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>