dtpicker null values, elegant solution?

  • Thread starter Thread starter Rob W
  • Start date Start date
R

Rob W

Greetings,

Within my applications which stores member details is a date field (last
visited), upon creating a new member this date can be left blank.

My application uses the checked function and if no date has been selected a
NULL date value is stored for the member record.

The edit member screen I use IsDBNull and only retrieve the datepicker value
if present.

Upon retrieving members where no date has been set it will display either
the default initial value (if first time in the form) or a value from the
previously selected record (which may confuse people).

I did think about using a strange initial date like 99/9/9999 (dd/mm/yyyy)
to indicate blank date.

Can anyone think of a more elegant solution?

I used a datepicker as I thought it would be convenient for the user.

I did think about custom controls but at my skill level of vb.net I would
rather avoid it, however if this is the ONLY real way forward I could brave
it ;-)

Any Ideas?

Thanks
Rob
 
today is the best idea i can think of :)For me the worst, because tomorrow it is yesterday

:-)

Cor
 
Rob,

Any not reachable date is correct. 1:1:1 (the same as a non set dateTime)
however it has to be a valid datetime and 99/9/9999 is that in not any
calendar which is used in the world.

I like to set it to 1-1-1753, which is the last date a western country
introduced the Gregorian Calendar (that last was the British Empire).

Before that date, the date is in fact nowhere correct if you don't know were
it was written.

Cor
 
Greetings,

Within my applications which stores member details is a date field (last
visited), upon creating a new member this date can be left blank.

My application uses the checked function and if no date has been selected a
NULL date value is stored for the member record.

The edit member screen I use IsDBNull and only retrieve the datepicker value
if present.

Upon retrieving members where no date has been set it will display either
the default initial value (if first time in the form) or a value from the
previously selected record (which may confuse people).

I did think about using a strange initial date like 99/9/9999 (dd/mm/yyyy)
to indicate blank date.

Can anyone think of a more elegant solution?

I used a datepicker as I thought it would be convenient for the user.

I did think about custom controls but at my skill level of vb.net I would
rather avoid it, however if this is the ONLY real way forward I could brave
it ;-)

Any Ideas?

Thanks
Rob

What we did is something like this:

Dim _userCustomFormat As String = "MM/dd/yyyy"
Dim _nullFormat As String = "'Date is Not Set'"

'On the next line, use whatever is appropriate to check if your date
is set or not.
If <Date is NOT NULL> Then
dtpAgreementDate.Value = <whatever the value should be>
dtpAgreementDate.CustomFormat = _userCustomFormat
Else
dtpAgreementDate.Value = DateTime.Now.AddDays(-1) 'Just some
value, put whatever you want here (or nothing)
dtpAgreementDate.CustomFormat = _nullFormat
EndIf

So if the date was not set, we would use a custom format. Notice in
the _nullFormat variable, that there are single quotes around the
text: " 'Date is Not Set' "

When set the format to your _nullFormat, the text inside the single
quotes will be displayed in the DateTimePicker regardless of the value
of the date.

Hope this helps,

Chris

Also, be sure to set the format property for the date time picker to
Custom.
 
Rob W said:
Greetings,

Within my applications which stores member details is a date field (last
visited), upon creating a new member this date can be left blank.

My application uses the checked function and if no date has been selected
a NULL date value is stored for the member record.

The edit member screen I use IsDBNull and only retrieve the datepicker
value if present.

Upon retrieving members where no date has been set it will display either
the default initial value (if first time in the form) or a value from the
previously selected record (which may confuse people).

I did think about using a strange initial date like 99/9/9999 (dd/mm/yyyy)
to indicate blank date.

Can anyone think of a more elegant solution?

I used a datepicker as I thought it would be convenient for the user.

I did think about custom controls but at my skill level of vb.net I would
rather avoid it, however if this is the ONLY real way forward I could
brave it ;-)

Any Ideas?

Thanks
Rob
What date value you return depends on what you use it for. If you're
returning a string value to print, use a word value like "unassigned" which
coincidentally is the same length as "MM/DD/YYYY". If you're attempting to
populate a control to let them enter a date, why return any value at all?
Just check IF <datefield> IsNot Nothing then populate control else execute
control clear method. If you really want an actual date value, I would
guess you'd want the oldest possible date which could be 1/1/1, or 1/1/100
to prevent confusion with 1/1/2001 where 2 digit year entry is allowed.
 
Back
Top