article

OOP Nullable DatePicker Control

Email
Submitted on: 1/5/2015 3:32:00 AM
By: VBRocks (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: VB.NET
Views: 2965
 
     Unfortunately, Microsoft's DateTimePicker control falls drastically short when it comes to being able to bind to data source properties that contain the data type of Nullable(Of Date). So I have created a simple DatePicker control that has a Value property of Nullable(Of Date) that can be bound to datasource properties of the same data type.

This article has accompanying files

 
				I created a DatePicker library in VB.NET 2005 that can be referenced from any project.

This DatePicker control can be bound to any object property that has a data type of Nullable(Of Date): if a date is selected by the user, then the control returns the date, however, if no date is selected by the user, then it returns Nothing.

Using the DataPicker control is easy and straight-forward. But one important note is that when binding to the DatePicker, it is necessary to set the formattingEnabled property to True.

Here's an example of binding the DatePicker control to an Employee BindingSource:
dpHireDate.DataBindings.Add("Value", _ m_bsEmployee, "HireDate", True)

The "HireDate" property of the Employee class is a Nullable(Of Date) property, and looks like this:
Private m_hireDate As Nullable(Of Date) = Nothing
'''
''' Gets or sets the Nullable HireDate
'''

Public Property HireDate() As Nullable(Of Date)
Get
Return m_hireDate
End Get
Set(ByVal value As Nullable(Of Date))
m_hireDate = value
End Set
End Property

Included is the zipped VS 2005 solution that demonstrates how to use the DatePicker control.

I hope it's helpful to you!

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 5 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.