Click here to Skip to main content
Licence 
First Posted 11 Nov 2003
Views 220,400
Downloads 2,878
Bookmarked 46 times

Nullable DateTimePicker

By Pham Minh Tri | 17 Nov 2003
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.
1 vote, 3.1%
1
1 vote, 3.1%
2
1 vote, 3.1%
3
6 votes, 18.8%
4
23 votes, 71.9%
5
4.74/5 - 32 votes
2 removed
μ 4.57, σa 1.68 [?]

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

About the Author

Pham Minh Tri



Vietnam Vietnam

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralRe: Small correction - an enhancement to that correction BugFixing x 2 PinmemberLeonunicorn4:42 4 Jan '10  
QuestionNull Button? PinmemberKysonel10:48 28 Mar '06  
QuestionHow to use? Pinmemberstrent006:54 21 Dec '05  
GeneralCool! PinmemberSuper Lloyd17:36 19 Dec '05  
GeneralClicking on current date in dropdown doesn't show datetime Pinmemberjfk80@wp.pl3:38 15 Mar '05  
Generalbind data to date time picker Pinmemberccloon23:11 20 Feb '05  
GeneralRe: bind data to date time picker PinmemberClaudio Grazioli11:36 28 Mar '05  
ccloon wrote:
i am using sql server and vb.net 2002 to develop my project.
the problem i face now is when i bind the null value (datatype = datetime) into the date time picker control, it show an error

 
Have a look at this version of a nullable date time picker.
http://www.omnitalented.com/Blog/PermaLink,guid,9ee757fe-a3e8-46f7-ad04-ef7070934dc8.aspx
It can handle "real" null values as you get them from databases.
 
You request it in VB. I'm sorry, it's in C#. But it's simple. I'm sure you manage to translate it.
 
Claudio Grazioli
http://www.grazioli.ch
GeneralRe: bind data to date time picker PinmemberClaudio Grazioli23:45 24 May '05  
AnswerRe: bind data to date time picker Pinmemberalc_aardvark7:07 14 May '08  
GeneralRe: bind data to date time picker PinmemberRoonda20:13 6 Apr '09  
GeneralDisplay blank space when NULL PinmemberSupaHoopsa5:56 9 Feb '05  
GeneralRe: Display blank space when NULL PinmemberClaudio Grazioli23:16 19 Apr '05  
GeneralThank you Pinmemberjanine_olley5:37 12 Oct '04  
General"Error creating window handle error" on TabControl control PinmemberSMiLEZ9:11 28 Sep '04  
GeneralRe: "Error creating window handle error" on TabControl control PinmemberBrett Zimmerman17:00 5 Oct '04  
GeneralRe: "Error creating window handle error" on TabControl control PinmemberClaudio Grazioli22:02 18 Apr '05  
GeneralThanks PinmemberTom Fischer5:30 18 Jun '04  
GeneralCould you have vb.net version PinmemberTony Dong12:10 25 May '04  
GeneralNice control, but ... PinmemberSachaMartineau4:38 25 Feb '04  
GeneralRe: Nice control, but ... PinmemberChristian Graus13:40 25 May '04  
GeneralRe: Nice control, but ... PinmemberSteveHolland3:48 2 Feb '05  
QuestionOverrides value?? PinmemberEntLover4:32 12 Jan '04  
AnswerRe: Overrides value?? PinsussUDALO7:39 17 Feb '04  
GeneralAdd ShowUpDown property support Pinsussetranger18:11 2 Jan '04  
GeneralFiring OnValueChanged PinmemberSébastien Lorion16:38 26 Dec '03  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 18 Nov 2003
Article Copyright 2003 by Pham Minh Tri
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid