Click here to Skip to main content
15,888,351 members
Articles / Programming Languages / C#
Article

Nullable DateTimePicker

Rate me:
Please Sign up or sign in to vote.
4.84/5 (41 votes)
17 Nov 2003 417.7K   18.2K   54   60
A standard DateTimePicker control that enables users to enter null value. The fact that it's not intensively modified ensures that it has no potential errors.

Sample Image - Nullable_DateTimePicker.jpg

Introduction

I had do a research on a DateTimePicker that could enter null value and found a lot of solutions to it. But one major problem with those is that they behave quite different from the standard ones and may have many potential bugs, as a result it took time to test before using in a real application. I just found another simple solution that could solve this problem with a little modification, so it could promise no bugs :-).

Solution

I have overridden the Value property to accept Null value as DateTime.MinValue, while maintaining the validation of MinValue and MaxValue of the standard control. That's all there's to it.

Because it's so simple, there's not much to say about it. Please refer to code for details.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Vietnam Vietnam
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Small correction - an enhancement to that correction Pin
ccbt9-Sep-09 19:27
ccbt9-Sep-09 19:27 
GeneralRe: Small correction - an enhancement to that correction BugFixing =) [modified] Pin
Leonunicorn4-Dec-09 1:45
Leonunicorn4-Dec-09 1:45 
GeneralRe: Small correction - an enhancement to that correction BugFixing x 2 [modified] Pin
kipotlov11-Dec-09 6:14
kipotlov11-Dec-09 6:14 
GeneralRe: Small correction - an enhancement to that correction BugFixing x 2 Pin
Leonunicorn15-Dec-09 4:57
Leonunicorn15-Dec-09 4:57 
GeneralRe: Small correction - an enhancement to that correction BugFixing x 2 Pin
Leonunicorn4-Jan-10 3:42
Leonunicorn4-Jan-10 3:42 
GeneralRe: Small correction - an enhancement to that correction BugFixing =) [modified] Pin
Member 102369739-Feb-15 20:49
Member 102369739-Feb-15 20:49 
QuestionNull Button? Pin
Kysonel28-Mar-06 9:48
Kysonel28-Mar-06 9:48 
QuestionHow to use? Pin
strent0021-Dec-05 5:54
strent0021-Dec-05 5:54 
GeneralCool! Pin
Super Lloyd19-Dec-05 16:36
Super Lloyd19-Dec-05 16:36 
GeneralClicking on current date in dropdown doesn't show datetime Pin
jfk8015-Mar-05 2:38
jfk8015-Mar-05 2:38 
Generalbind data to date time picker Pin
ccloon20-Feb-05 22:11
ccloon20-Feb-05 22:11 
GeneralRe: bind data to date time picker Pin
Claudio Grazioli28-Mar-05 10:36
Claudio Grazioli28-Mar-05 10:36 
GeneralRe: bind data to date time picker Pin
Claudio Grazioli24-May-05 22:45
Claudio Grazioli24-May-05 22:45 
AnswerRe: bind data to date time picker Pin
alc_aardvark14-May-08 6:07
alc_aardvark14-May-08 6:07 
GeneralRe: bind data to date time picker Pin
Roonda6-Apr-09 19:13
Roonda6-Apr-09 19:13 
GeneralDisplay blank space when NULL Pin
SupaHoopsa9-Feb-05 4:56
SupaHoopsa9-Feb-05 4:56 
GeneralRe: Display blank space when NULL Pin
Claudio Grazioli19-Apr-05 22:16
Claudio Grazioli19-Apr-05 22:16 
GeneralThank you Pin
jhenstock12-Oct-04 4:37
jhenstock12-Oct-04 4:37 
General"Error creating window handle error" on TabControl control Pin
Mark Horlbeck28-Sep-04 8:11
Mark Horlbeck28-Sep-04 8:11 
GeneralRe: "Error creating window handle error" on TabControl control Pin
Member 9440325-Oct-04 16:00
Member 9440325-Oct-04 16:00 
GeneralRe: "Error creating window handle error" on TabControl control Pin
Claudio Grazioli18-Apr-05 21:02
Claudio Grazioli18-Apr-05 21:02 
GeneralThanks Pin
Tom Fischer18-Jun-04 4:30
Tom Fischer18-Jun-04 4:30 
GeneralCould you have vb.net version Pin
Tony Dong25-May-04 11:10
Tony Dong25-May-04 11:10 
GeneralNice control, but ... Pin
SachaMartineau25-Feb-04 3:38
SachaMartineau25-Feb-04 3:38 
GeneralRe: Nice control, but ... Pin
Christian Graus25-May-04 12:40
protectorChristian Graus25-May-04 12:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.