Search KB Filter article types
NullableDateTimePicker
Representing an empty DateTime value, like a NULL in a DateTime field coming from a database, requires some programming as the Value property in the DateTimePicker control is not NULLable, and will thrown an exception when assigned such a value. The NullableDateTimePicker extends the standard out-of-the-box DateTimePicker control, allowing it to store NULL values.
Categories: Date & Time, Skinnable and Inherited Controls
Tags: Developers, C#, 1. Beginner, 2. Intermediate, 3. Advanced, Customization, Pre v6.3, v6.3, v6.4 and Later, VB.NET
Revision: 6
Posted: 03/Jan/2008
Updated: 03/April/2011
Status: Publish
Types: Code

The NullableDateTimePicker class inherits from DateTimePicker.
The functionality is implemented via 2 new properties: NullValue and AllowNullValues.
· NullValue is an actual DateTime value that is used by the application to represent null. By default, this is set to 01/01/01, but can be changed programmatically.
· AllowNullValues is a boolean which indicates whether or not null values are allowed.

For example: objNullableDateTimePicker.Value = null;
Executing the above statement has the following consequences:
· If AllowNullValues is true, the Value property will be set equal to the NullValue property, otherwise an ArgumentNullException is thrown.
· Trying to set AllowNullValues to false when the Value property is equal to the NullValue throws an ArgumentException.

 

Note: Codes are submitted as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Terms of Agreement:
By using this code, you agree to the following terms...

1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3. You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

Download for VS2005 & C# only, pre 6.4Download for VS2005, VS2008 & VS2010, C# and VB.NET for 6.4 and later

About the author

Related Articles

Date & Time  
Title Update Author
Tags: Architects, Developers, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Architects, Developers, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Architects, Developers, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
21/July/2010    2010/07/21
Hi everyone, I develop a simple inputbox class with some features like value checking, maximum value size, etc. It is used as the MessageBox class and you can modify it at your needs. Check the attached sample application. Regards, Scott.
Tags: Developers, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
02/Jan/2010    2010/01/02
Tags: Developers, Data Binding, 2. Intermediate, 3. Advanced, Customization, Layouting, Pre v6.3, v6.3, v6.4 and Later
05/Jan/2009    2009/01/05
Tags: Developers, Gateway, 2. Intermediate, 3. Advanced, Customization, Integration, Pre v6.3, v6.3, v6.4 and Later
09/Jan/2008    2008/01/09
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS