Date Time Picker Question

  • Thread starter Thread starter XmlAdoNewbie
  • Start date Start date
X

XmlAdoNewbie

Hi All,
I am wondering if it is possible to allow nulls or empty strings when
it comes to the datetimepicker control. I have an app with a few
datetimepickers on it and there are some instances when i don't want a
date to show at all but the datetimepickers always have at least
todays date in it so when i go to press the save button on my app
there is always a date stored in the retrieved field. Is there a way
to say "hey i don't want a date stored in this field, i want "" or
null"
thanks
Erin
 
Hi Erin,
Hi All,
I am wondering if it is possible to allow nulls or empty strings when
it comes to the datetimepicker control. I have an app with a few
datetimepickers on it and there are some instances when i don't want a
date to show at all but the datetimepickers always have at least
todays date in it so when i go to press the save button on my app
there is always a date stored in the retrieved field. Is there a way
to say "hey i don't want a date stored in this field, i want "" or
null"
thanks
Erin

Some time ago i want to make a null visible in DateTimePicker but i
found it is impossible.

Only thing You can do is:
1) Using tricks to set null value e.g. by handling KeyDown event "Delete"

or

2) Writing Your own control based on TextBox or use two controls.
- Replace TextBox with DateTimePicker on Enter
- Hide DateTimePicker on Leave and store (or remove) value.

If You'll find any easier way the let me know at:
mgrzebski(at)taxussi.com.pl

Regards

Marcin
 
You can try something like this:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.DateTimePicker1.Format = DateTimePickerFormat.Custom

Me.DateTimePicker1.CustomFormat = " "

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.DateTimePicker1.Format = DateTimePickerFormat.Custom

Me.DateTimePicker1.CustomFormat = " "

End Sub

Private Sub DateTimePicker1_DropDown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DateTimePicker1.DropDown

Me.DateTimePicker1.CustomFormat = "yyyy/MM/dd"

End Sub

Private Sub DateTimePicker1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles DateTimePicker1.KeyDown

If e.KeyCode = Keys.Delete Then

Me.DateTimePicker1.CustomFormat = " "

ElseIf Me.DateTimePicker1.CustomFormat = " " AndAlso _

(e.KeyValue >= 48 AndAlso e.KeyValue <= 57) OrElse _

(e.KeyValue >= 96 AndAlso e.KeyValue <= 105) _

Then

Me.DateTimePicker1.CustomFormat = "yyyy/MM/dd"

End If

End Sub


--

HTH

Éric Moreau, MCSD
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
Hi Eric,
Thanks so much for your post. It works in that it shows a blank date in
the date time picker however when i go to retrieve the value out of the
date time picker it still gives me today's date. I would like the value
to be an empty string if the date time picker is showing a blank, is
this possible??
Thanks
Erin
 
You may validate if Me.DateTimePicker1.CustomFormat = " "

--

HTH

Éric Moreau, MCSD
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
Back
Top