R
Richard Lewis Haggard
Is there some way to have the DateTimePicker display nothing? I came up with
a hack but I was hoping that there was a less offensive method than the
horrid little code snippet that fell out of my fingers when I wasn't paying
attention.
Here's why I need to have the date time picker be able to not display date
information. My client wants to display nothing if the underlying data model
does not have a datetime value. If the user sets focus in the control then
the client wants the date time picker to immediately light up with a default
date time. If the user leaves the control without entering a value then it
goes blank again. Otherwise, it hangs on to the user's entered value from
then on.
Here's the hack. When the form is first shown, display the date time picker
if the data model's date time is valid. Otherwise, hide the date time picker
and display a text box where the date time picker would have been. When text
box receives focus, hide the text box, show the date time picker and
transfer the focus to the date time picker. On leaving the date time picker,
hide the date time picker and display the text box if the user did not enter
in a value. If the user did specify a value then leave the date time picker
visible and the text box remains hidden.
Most of this horrid little code snippet works just fine (or at least as well
as one might hope for). However, there is a problem with the text box's tab
index. It is set with the same value as the date time picker's but it
insists on being someplace very different in the tabbing order. Why is this
and how can I fix it?
A second little puzzle has to do with the date time picker's Leave event
handler being called in response to calling dateTimePicker.Focus(). Why is
the Leave event being called? How do I stop this?
a hack but I was hoping that there was a less offensive method than the
horrid little code snippet that fell out of my fingers when I wasn't paying
attention.
Here's why I need to have the date time picker be able to not display date
information. My client wants to display nothing if the underlying data model
does not have a datetime value. If the user sets focus in the control then
the client wants the date time picker to immediately light up with a default
date time. If the user leaves the control without entering a value then it
goes blank again. Otherwise, it hangs on to the user's entered value from
then on.
Here's the hack. When the form is first shown, display the date time picker
if the data model's date time is valid. Otherwise, hide the date time picker
and display a text box where the date time picker would have been. When text
box receives focus, hide the text box, show the date time picker and
transfer the focus to the date time picker. On leaving the date time picker,
hide the date time picker and display the text box if the user did not enter
in a value. If the user did specify a value then leave the date time picker
visible and the text box remains hidden.
Most of this horrid little code snippet works just fine (or at least as well
as one might hope for). However, there is a problem with the text box's tab
index. It is set with the same value as the date time picker's but it
insists on being someplace very different in the tabbing order. Why is this
and how can I fix it?
A second little puzzle has to do with the date time picker's Leave event
handler being called in response to calling dateTimePicker.Focus(). Why is
the Leave event being called? How do I stop this?