Click here to Skip to main content
6,594,088 members and growing! (14,748 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

Date Control Better then DateTimePicker

By Muhammad Abubakar Dar

Assumed to makes possible input of date values as fast as user can via keyboard also has ability to pick date from picker like tradition DateTimePicker
VB.NET 1.1, Win2K, WinXPVS.NET2003, Architect, DBA, Dev, QA
Posted:29 Mar 2006
Views:57,027
Bookmarked:27 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 4.35 Rating: 3.61 out of 5
2 votes, 12.5%
1
3 votes, 18.8%
2
2 votes, 12.5%
3
1 vote, 6.3%
4
8 votes, 50.0%
5

Sample Image - Better_Date_Time_Picker.gif

Background

In a database application Date data type handling is a bit difficult as compared to other data types and getting input by keyboard is required some extra efforts. Common solution to this problem is the DateTimePicker control provided by Microsoft. Unfortunately DateTimePicker is not best suited for fast data entry via keyboard that is always required in a database driven applications. I have got several complains from end users that he don�t want to use mouse for date selection or when entering date in DateTimePicker via keyboard require extra keys has to be pressed from moving 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 data fast and in alternate ways either by keyboard or by using mouse.

 

Introduction

 

What I have done is, created a textbox masked control to input date via 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 than 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 DateTimePicker with value entered in TextBox , DateTimePicker will generate an exception for 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 drop on the form you want to use. I am giving you people here the over view of properties that can be used while in design time and run time

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

 

Custom Properties, events, methods, their description and reason why I have created

the specific is as follows:

 

Properties

 

Value

Returns the value in the form of date; same as of DateTimePicker

Day    

Is same as in DateTimePicker�s �Value.Day�  statement, but u will get one step in advance, simply �Control1.Day�.

Month

           Is same as in DateTimePicker�s �Value.Month�  statement, but u will get one step in advance, simply �Control1.Month�.

Year   

            Is same as in DateTimePicker�s �Value.Year�  statement, but u will get one step in advance, simply �Control1.Year�.

SQL Value     

            The specific property required when using the value of DateTimePicker with SQLServer, Because SQL Server requires a date format of �yyyy\MM\dd� to work fine .This property returns the Formated Date.

DateFormat   

           Specify Date Format you want to use, currently there are three supported formats DMY,MDY,YDM

IsValid           

           A ReadOnly property that return the state of the control. This property can be used for validating form input before submitting back to DBMS.

 

AllowNull       

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

Events

ValueChanged           

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

Methods

            Clear 

 It can be used to clear the date if AllowNull is set to true then it will set value property to Null and clear the text of the control otherwise set the control text to current date and value accordingly.

 

About The Author        

                               anti.genius@yahoo.com

 

 

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

Muhammad Abubakar Dar


Member

Occupation: Software Developer (Senior)
Company: Systems Limited
Location: Pakistan Pakistan

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
GeneralRecommendations to a great control Pinmemberkevinlkingma6:03 8 Dec '08  
General.NET 2.0 PinmemberSuneelan2:56 5 Oct '07  
GeneralC# Source File PinmemberMary_m8:33 14 Sep '07  
GeneralDataBinding Pinmembercagla1210:30 11 May '07  
GeneralPassword for Source? PinmemberDaryl_Saunders18:14 26 Jan '07  
GeneralNot quite there Pinmemberl2l223:53 16 Nov '06  
QuestionData Binding Pinmemberhwdevelop8:42 16 Nov '06  
GeneralGreat control PinmemberPinx12:03 13 Nov '06  
GeneralExcellent for superfast date entry! PinmemberCygNuZ23:50 9 Oct '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Mar 2006
Editor:
Copyright 2006 by Muhammad Abubakar Dar
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project