Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2007

Tip: Looking for answers? Try searching our database.

DateTimePicker - how to show nothing when user has not specified a date?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard Lewis Haggard - 17 Jul 2007 15:31 GMT
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?
Signature

Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm

Sheng Jiang[MVP] - 17 Jul 2007 17:56 GMT
Set the ShowCheckBox property and the Checked property

Signature

Sheng Jiang
Microsoft MVP in VC++

> 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
[quoted text clipped - 27 lines]
> handler being called in response to calling dateTimePicker.Focus(). Why is
> the Leave event being called? How do I stop this?
Richard Lewis Haggard - 17 Jul 2007 19:34 GMT
Thanks for the pointer. Sadly, my client has already rejected that behavior.
He wants a blank control until such time as the user actively wants to edit
the date time, hence the questions that I asked.
Signature

Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm

> Set the ShowCheckBox property and the Checked property
>
[quoted text clipped - 46 lines]
>> is
>> the Leave event being called? How do I stop this?
Richard Lewis Haggard - 17 Jul 2007 20:21 GMT
TabIndex - a control's tab order is not responsive to setting its TabIndex.
Instead, it can be set through the control parent's
Controls.SetChildIndex( childControl, newIndex ) method.

DateTimePicker gets Leave event notification on dateTimePicker.SetFocus() -
As for the date time picker getting a Leave event notification after focus
was programmatically set to the control, I never did figure that out. I got
around the problem by simply adding a bool that was set when the code set
focus to the date time control. The Leave event looked at the bool and said,
"Ah. This is a spurious event. I do not need to make sure that the text box
is on top of me. Oh yes, the bool must be cleared, too."
Signature

Richard Lewis Haggard
General: www.Haggard-And-Associates.com
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm

> 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
[quoted text clipped - 27 lines]
> handler being called in response to calling dateTimePicker.Focus(). Why is
> the Leave event being called? How do I stop this?
VisualHint - 25 Jul 2007 21:42 GMT
Hello Richard,

the DateTimePicker class and underlying win32 object are not flexible
at all. That's why I created Smart FieldPackEditor.Net, an editor
capable of editing rule-based fields. The DateTimePicker is an example
(I just added another one which is the IP address editor). I rewrote
it from scratch and if you want to give it a try you will get the
flexibility you want. It is currently in beta and you can play with
it. There is a sample and many screencasts to see it in action.

Best regards,

Nicolas Cadilhac @ VisualHint (http://www.visualhint.com)
Home of Smart FieldPackEditor.Net / DateTimePicker replacement
Home of Smart PropertyGrid for .Net and MFC
Microsoft PropertyGrid Resource List - http://www.propertygridresourcelist.com

On Jul 17, 10:31 am, "Richard Lewis Haggard"
<HaggardAtWorldDotStdDotCom> wrote:
> Is there some way to have theDateTimePickerdisplay nothing? I came up with
> a hack but I was hoping that there was a less offensive method than the
[quoted text clipped - 31 lines]
> General:www.Haggard-And-Associates.com
> Please come visit here for a couple thousand good giggles!:www.haggard-and-associates.com/Humor/humor.htm

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.