Click here to Skip to main content
15,886,258 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.6K   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

 
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 
GeneralRe: Nice control, but ... Pin
SteveHolland2-Feb-05 2:48
SteveHolland2-Feb-05 2:48 
QuestionOverrides value?? Pin
EntLover12-Jan-04 3:32
EntLover12-Jan-04 3:32 
AnswerRe: Overrides value?? Pin
UDALO17-Feb-04 6:39
sussUDALO17-Feb-04 6:39 
GeneralAdd ShowUpDown property support Pin
Sebastien Arcand2-Jan-04 17:11
Sebastien Arcand2-Jan-04 17:11 
You can add support to the ShowUpDown property usually used for Time Format:

protected override void OnMouseUp(MouseEventArgs e)
{
if(this.ShowUpDown)
{
if (bIsNull)
{
this.Format = oldFormat;
this.CustomFormat = oldCustomFormat;
this.Value = DateTime.Now;
bIsNull = false;
}
}

base.OnMouseUp(e);
}
GeneralFiring OnValueChanged Pin
Sebastien Lorion26-Dec-03 15:38
Sebastien Lorion26-Dec-03 15:38 
GeneralRe: Firing OnValueChanged Pin
Balaji Vishnumolakala4-Nov-04 4:07
Balaji Vishnumolakala4-Nov-04 4:07 
GeneralSelecting the control with Tab Pin
Mortens_HUN7-Mar-07 0:47
Mortens_HUN7-Mar-07 0:47 
GeneralHelp! Pin
kvc13-Dec-03 3:47
kvc13-Dec-03 3:47 
Generalimplementation Pin
kvc12-Dec-03 8:10
kvc12-Dec-03 8:10 
GeneralRe: implementation Pin
Pham Minh Tri16-Dec-03 19:34
Pham Minh Tri16-Dec-03 19:34 

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.