By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,928 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,928 IT Pros & Developers. It's quick & easy.

Date Time Picker Question

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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
Nov 16 '05 #2

P: n/a
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)
"XmlAdoNewbie" <er************@cowaninsurancegroup.com> wrote in message
news:c9**************************@posting.google.c om...
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

Nov 16 '05 #3

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

P: n/a
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)
"XmlAdoNewbie" <er************@cowaninsurancegroup.com> wrote in message
news:c9**************************@posting.google.c om...
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

Nov 16 '05 #5

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

P: n/a
You may validate if Me.DateTimePicker1.CustomFormat = " "

--

HTH

Éric Moreau, MCSD
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
"Erin Sebastian" <er************@cowaninsurancegroup.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #7

P: n/a
You may validate if Me.DateTimePicker1.CustomFormat = " "

--

HTH

Éric Moreau, MCSD
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
"Erin Sebastian" <er************@cowaninsurancegroup.com> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.