By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

Date/Time Pickers/VB2005

P: n/a
I'm building a database application that has a number of date fields in it.
When I add the date/time picker control to my form and run it, if the field
is null in my db, then it shows the current date. How can I get this
control to be blank when the corresponding field in my db is blank?

Thanks!

Darhl
Sep 7 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Darhl Thomason wrote:
I'm building a database application that has a number of date fields in it.
When I add the date/time picker control to my form and run it, if the field
is null in my db, then it shows the current date. How can I get this
control to be blank when the corresponding field in my db is blank?
There is no built in support in the control for null dates. Here's
what I did:

First I create two string to hold the date format. Note that the Not
Specified string includes an apostrophe (') at each end. 'Not
Specified'

Dim _userCustomFormat As String = "MM/dd/yyyy"
Dim _nullFormat As String = "'Not Specified'"

On the DateTimePicker control, set the format to Custom

Then in the code, check to see if the date is null (Nothing) and if so,
us the _nullFormat, otherwise use your desired date format:

If _dateVariable.HasValue Then
dtpDate.Value = _currentEmployee.AgreementDate.Value
dtpDate.CustomFormat = _userCustomFormat
Else
dtpDate.Value = DateTime.MinValue
dtpDate.CustomFormat = _nullFormat
End If

Hope this gives you some ideas.

Sep 7 '06 #2

P: n/a
"Darhl Thomason" <da****@papamurphys.nospamplease.comschrieb:
I'm building a database application that has a number of date fields in
it. When I add the date/time picker control to my form and run it, if the
field is null in my db, then it shows the current date. How can I get
this control to be blank when the corresponding field in my db is blank?
Untested:

<URL:http://www.grazioli.ch/Blog/PermaLink.aspx?guid=c4a63d35-71f9-4b02-9de7-0c87e5b1c770>

Nullable DateTimePicker
<URL:http://www.codeproject.com/cs/miscctrl/Nullable_DateTimePicker.asp>

(For a translation to VB.NET, take a look at the comments section of the
page.)

You may want to set the 'ShowCheckBox' property to 'True' and use the
checkbox as a null value indicator (if 'Checked' is 'False', no date is
selected). Notice that the 'ShowCheckBox' property is flawed and thus this
is not the best way.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Sep 7 '06 #3

P: n/a
Thanks Chris,

I know you're just making names up because you don't know my db, but I don't
know how to pull the value of my date field. You're using "_dateVariable"
and "_currentEmployee.AgreementDate" and I don't know where they come
from...I'm assuming these are variables that get assigned somewhere. I get
the concept of this, but am struggling with how/where to assign my values.

Can I put this into a loop? I've got 6 dtp controls...so could I do
something like:
For Each dtp in frmStoreData
if/then...
else...
endif...
Next

Darhl
"Chris Dunaway" <du******@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Darhl Thomason wrote:
>I'm building a database application that has a number of date fields in
it.
When I add the date/time picker control to my form and run it, if the
field
is null in my db, then it shows the current date. How can I get this
control to be blank when the corresponding field in my db is blank?

There is no built in support in the control for null dates. Here's
what I did:

First I create two string to hold the date format. Note that the Not
Specified string includes an apostrophe (') at each end. 'Not
Specified'

Dim _userCustomFormat As String = "MM/dd/yyyy"
Dim _nullFormat As String = "'Not Specified'"

On the DateTimePicker control, set the format to Custom

Then in the code, check to see if the date is null (Nothing) and if so,
us the _nullFormat, otherwise use your desired date format:

If _dateVariable.HasValue Then
dtpDate.Value = _currentEmployee.AgreementDate.Value
dtpDate.CustomFormat = _userCustomFormat
Else
dtpDate.Value = DateTime.MinValue
dtpDate.CustomFormat = _nullFormat
End If

Hope this gives you some ideas.

Sep 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.