Friday, January 14, 2011

Assigning a null value to DateTimePicker(.Net Framework)

In the my few years since I joined the software Development , About half of the application I wrote I was required to allow the user to changed or enter a date field which came as a very easy task since Microsoft .Net has a DateTimePicker Control which works perfectly fine, the user can interact with it and you can get the value of DateTime type, which is awesome. Until i reached a point where I got data from a nullable database field which held the date value i have to display on my User Interface's DateTimePicker control, Unfortunately my favorite Microsoft .NET DateTimePicker doesn't accept null as a value plus you can not clear the display which by default it displays the current date, The client want to see a blank field if the date value is null on the database, which to me makes sense, I shouldn't see anything if the is nothing right?.

Went back to the drawing board, did my research and I found that you really can't clear the DateTimePicker control, MSDN also confirmed that. Now my head grew bigger each minute, until it crossed my mind that i can actually create my own custom control the can behave the way I want it to or use one of the third party controls i found on the internet, but writing my own control will add to my skills development, so I decided to write it,  how cool is that? I managed to extend the DateTimePicker to behave the way I want I to, Ill be posting an article on how i created the control and ill also provide sample code and the complete project just in case you where siting with the similar problem as mine.  

No comments:

Post a Comment