Using Null in DateTimePickers

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hey folks,

I have a DateTimePicker control on my Windows Form. Whenever I either:
a) Don't give it a value
b) Set it's value to Null
c) Set it's value to ""
It makes the date today's date.

I need it to be empty though. How do I make it empty? It represents a
field in my database which legitimately can be null and so I can't show it
as todays date.

Thanks a lot for the help!



(I posted a similar message a couple of days ago without a response, but
it's really important and time is of the essence so I'm trying again)
 
John,

Unfortunately, the DateTimePicker doesn't support this. The best way to
do this is to have a checkbox to indicate whether or not it has a value.

Hope this helps.
 
John said:
Hey folks,

I have a DateTimePicker control on my Windows Form. Whenever I either:
a) Don't give it a value
b) Set it's value to Null
c) Set it's value to ""
It makes the date today's date.

I need it to be empty though. How do I make it empty? It represents a
field in my database which legitimately can be null and so I can't show it
as todays date.

Thanks a lot for the help!

As Nicholas states, the DateTimePicker from MS does not support null.
There are third party controls that do. Infragistics
(www.infragistics.com) NetAdvantage Suite includes a calendar control
that supports null.
 
Hi Jon,


I want to add an approach that I used once in a web app, as DateTime does
not support null you need to define a null value inside its range, I
selected a date that was not possible in my domain ( I think you could also
use DateTime.MinDate ), so what I do is assign it as the selectedDate, but I
set the visible Date to today, therefore the controls is happy cause it has
a value and as this value is way outside the domain it will never be
displayed.

Maybe this does not solve your problem 100% but it may give you other
ideas.

Cheers,
 
Thanks...the problem is though that if it's displaying today's date...the
user may think that is what is in the database and take action based upon
that.
 
Hi,

What you can do is make clear than a date has not being selected, just
create a new control with a datetimepicker and a label, the label may
display some text for the user.

Cheers,
 

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