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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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/d...systemwindowsformserrorproviderclasstopic.asp

I hope this helps,

Cor
 
Eduardo78 said:
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.
 
Eduardo78 said:
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.)
 

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

Back
Top