Click here to Skip to main content
11,922,877 members (56,729 online)
Click here to Skip to main content
Add your own
alternative version


34 bookmarked

A date control better than DateTimePicker

, 29 Mar 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Makes the input of date values as fast as the user can via keyboard. Also has the ability to pick date from a picker like in the traditional DateTimePicker.

Sample Image - Better_Date_Time_Picker.gif


In a database application, date handling is a bit difficult as compared to validating other data types, and getting input by keyboard requires some extra effort. The common solution to this problem is the DateTimePicker control provided by Microsoft. Unfortunately, DateTimePicker is not the best suited for fast data entry via keyboard that is always required in database driven applications. I get several complaints from end users that they don’t want to use the mouse for date selection, or that when entering date in a DateTimePicker via keyboard, it requires extra keys to be pressed from moving the cursor from one day part to next, and so on. This is the motivation behind the development of a new DateTimePicker, which will enable users to enter dates faster and in alternate ways either by using the keyboard or by using the mouse.


What I have done is, created a textbox masked control to input date via the keyboard, and also attached a DateTimePicker control to input date via mouse. It also has the functionality to validate user input if the date is not valid, and then the text color is displayed in red. Also, set its property “IsValid” to false. To validate date, what I have done is a trick: just set the value of the DateTimePicker with the value entered in the TextBox, and the DateTimePicker will generate an exception for an invalid date value and the color will change to red.

Using the Control

It is quite easy to use like other controls. Just add to your toolbox, and drop it on the form you want to use. I will give here an overview of the properties that can be used during design time and at run time.

I have tried to expose properties just like in the DateTimePicker, so if you are going to replace DateTimePicker from your existing project with this one, you don’t have to change your code.


  • Value
  • Returns the value in the form of date; same as in DateTimePicker.

  • Day
  • Same as DateTimePicker’s ‘Value.Day’, but you will get one step in advance, simply ‘Control1.Day’.

  • Month
  • Same as in DateTimePicker’s ‘Value.Month’, but you will get one step in advance, simply ‘Control1.Month’.

  • Year
  • Same as in DateTimePicker’s ‘Value.Year’, but you will get one step in advance, simply ‘Control1.Year’.

  • SQLValue
  • The specific property required when using the value of DateTimePicker with SQL Server, because SQL Server requires a date format of “yyyy\MM\dd” to work fine. This property returns the formatted date.

  • DateFormat
  • Specify the date format you want to use; currently, there are three supported formats: DMY, MDY, YDM.

  • IsValid
  • A read-only property that returns the state of the control. This property can be used for validating the form input before submitting back to the DBMS.

  • AllowNull
  • This property is used to replace the checkbox that is displayed with the default DateTimePicker, that often creates a problem whenever you try to check or uncheck it in code. So for now, when we need to have a null-able date column, this property will be used either to allow a null or not. It will return null if the textbox is empty, which means the user doesn’t want to enter the date.


  • ValueChanged
  • You can write your custom code for the value changed event as we write for DateTimePicker.


  • Clear
  • It can be used to clear the date if AllowNull is set to true; then it will set the value property to null and clear the text of the control; otherwise, sets the control text to the current date and value accordingly.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Muhammad Abubakar Dar
Software Developer (Senior) Systems Limited
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

Answerthnkz for this control Pin
Pachacutec236-Sep-12 10:15
memberPachacutec236-Sep-12 10:15 
QuestionDate Time Picker Pin
Ken Beale1-Apr-12 3:24
memberKen Beale1-Apr-12 3:24 
QuestionDatabinding and Parse event Pin
e_ch16-Sep-11 10:35
membere_ch16-Sep-11 10:35 
GeneralRecommendations to a great control Pin
kevinlkingma8-Dec-08 6:03
memberkevinlkingma8-Dec-08 6:03 
General.NET 2.0 Pin
Suneelan5-Oct-07 2:56
memberSuneelan5-Oct-07 2:56 
GeneralC# Source File Pin
Mary_m14-Sep-07 8:33
memberMary_m14-Sep-07 8:33 
GeneralDataBinding Pin
cagla1211-May-07 10:30
membercagla1211-May-07 10:30 
QuestionPassword for Source? Pin
Daryl_Saunders26-Jan-07 18:14
memberDaryl_Saunders26-Jan-07 18:14 
GeneralNot quite there Pin
l2l216-Nov-06 23:53
memberl2l216-Nov-06 23:53 
QuestionData Binding Pin
hwdevelop16-Nov-06 8:42
memberhwdevelop16-Nov-06 8:42 
GeneralGreat control Pin
Pinx13-Nov-06 12:03
memberPinx13-Nov-06 12:03 
GeneralExcellent for superfast date entry! Pin
CygNuZ9-Oct-06 23:50
memberCygNuZ9-Oct-06 23:50 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151125.1 | Last Updated 30 Mar 2006
Article Copyright 2006 by Muhammad Abubakar Dar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid