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 / May 2007

Tip: Looking for answers? Try searching our database.

DateTimePicker.Value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mahesh.nimbalkar@gmail.com - 31 May 2007 14:27 GMT
Hi,

I have DateTimePicker control on a winform. When user selects a date
in that control, I am getting proper value using DateTimePicker.Value.
But I want to know in case user does not select any date and closes
DateTimePicker control by pressing escape key. Here in this case also
I am getting today's date even if user did not select any date in that
control.

I should get null or something else that will let me know that user
did not select anything and closed the DateTimePicker by pressing
escape key.

Any idea how to do that?

Thanks!
VR Ravinuthala - 31 May 2007 15:24 GMT
You can set the date to DateTime.MinValue
instead of today's date.

You can identify the chagne by using the events

ValueChanged
and
ChangeUICues

to identify the change.

-VR

> Hi,
>
[quoted text clipped - 12 lines]
>
> Thanks!
mahesh.nimbalkar@gmail.com - 31 May 2007 16:23 GMT
Thanks for the reply.

The user can select whatever date shown in the control so I can not
come to know whether user has really selected any value or pressed
escape key because in both cases I will get same value.

On May 31, 10:24 am, VR Ravinuthala
<VRRavinuth...@discussions.microsoft.com> wrote:
> You can set the date to DateTime.MinValue
> instead of today's date.
[quoted text clipped - 26 lines]
>
> > Thanks!
VisualHint - 31 May 2007 15:24 GMT
Hello Mahesh,

If the user does not select a date and presses Esc, then you get the
current value (the one that was shown before showing the drop down
calendar) when you call Value. This is normal and what is expected.

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 May 31, 9:27 am, mahesh.nimbal...@gmail.com wrote:
> Hi,
>
[quoted text clipped - 11 lines]
>
> Thanks!
mahesh.nimbalkar@gmail.com - 31 May 2007 16:21 GMT
Thanks for the reply.

User can select what is shown in the control while displaying that
control. So I can not come to know that whether you has selected the
date or pressed escape key.

Thanks

> Hello Mahesh,
>
[quoted text clipped - 26 lines]
>
> > Thanks!
VisualHint - 31 May 2007 18:20 GMT
I'm not sure to understand what you mean.
As another poster added, when the user selects a date you will get a
ValueChanged event. When he hits ESC you won't. This should allow you
to discriminate both cases.
You have also the CloseUp event so that you know when the dropdown is
closed.

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 May 31, 11:21 am, mahesh.nimbal...@gmail.com wrote:
> Thanks for the reply.
>
[quoted text clipped - 34 lines]
>
> > > Thanks!
mahesh.nimbalkar@gmail.com - 31 May 2007 18:24 GMT
I already tried ValueChanged event. But the problem with that is when
user opens DateTimePicker control and closes it by pressing escape,
even in this case also ValueChanged event gets fired.

> I'm not sure to understand what you mean.
> As another poster added, when the user selects a date you will get a
[quoted text clipped - 50 lines]
>
> > > > Thanks!
VisualHint - 31 May 2007 19:22 GMT
Indeed youre right. I just tried it. In fact you are partially right.
Until I modify the displayed date, ValueChanged will be triggered even
if ESC is hit. After a change it's not trigerred anymore on ESC. But
anyway, if the user types the arrow keys to move the cue in the month
calendar, ValueChanged is triggered and hitting ESC after would not
help. At least this allows you to see how this native control is
illogical. I am fixing all these oddities in Smart FieldPackEditor.

Anyway, maybe you should do things differently. What is your exact
goal ? If you want to know that ESC has been pressed, why not try to
detect the fact that ESC is actually typed instead of relying on the
Value property which won't never be null anyway...

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 May 31, 1:24 pm, mahesh.nimbal...@gmail.com wrote:
> I already tried ValueChanged event. But the problem with that is when
> user opens DateTimePicker control and closes it by pressing escape,
[quoted text clipped - 54 lines]
>
> > > > > Thanks!
mahesh.nimbalkar@gmail.com - 31 May 2007 19:47 GMT
On some event I am showing DateTimePicker control in open state. Now
if users selected date, I would do some processing and user presses
ESC, I would just ignore it.

I main point here is that I just wanted to know whether user has
selected any date or not. Because on that only I will be processing
some data.

I tried key press events also, but seems that if control is in open
state, it will not fire any keyboard events.

If you have any alternate solution to know if user has selected any
date in control, please let me know. I am stuck now.

Thanks!

> Indeed youre right. I just tried it. In fact you are partially right.
> Until I modify the displayed date, ValueChanged will be triggered even
[quoted text clipped - 76 lines]
>
> > > > > > Thanks!
VisualHint - 31 May 2007 19:56 GMT
When showing the picker in open state, why don't you record the
initial date? When the CloseUp event occurs you would simply compare
the old date with the one returned by Value... Not enough?

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 May 31, 2:47 pm, mahesh.nimbal...@gmail.com wrote:
> On some event I am showing DateTimePicker control in open state. Now
> if users selected date, I would do some processing and user presses
[quoted text clipped - 92 lines]
>
> > > > > > > Thanks!
mahesh.nimbalkar@gmail.com - 31 May 2007 20:26 GMT
Yes it will work except one case and that is not acceptable. The case
is, user can select whatever is the default date shown in the
DateTimePicker control and here I will not come to know that user has
actually selected a date and not pressed ESC key if I compare default
date with currently selected date.

> When showing the picker in open state, why don't you record the
> initial date? When the CloseUp event occurs you would simply compare
[quoted text clipped - 105 lines]
>
> > > > > > > > Thanks!
VisualHint - 31 May 2007 21:12 GMT
What you want to do is not so easy and maybe you should rethink the
way you do it (showing the datetimepicker opened initially is not very
intuitive and consistent with the OS after all). In Smart PropertyGrid
I was using the MS DateTimePicker and I gave up because I was not able
to achieve the same level of quality and usability than the other
editors. At the end, I had reached a point where I had some message,
keyboard and mouse hooks on the calendar popup and even then there was
always something not satisfying. This has been the trigger to start a
complete DateTimePicker replacement and I think this will be a real
success.

If you still want to go on this path, try to get the handle of the
calendar and hook various messages so that you know what happens with
the user interaction.

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 May 31, 3:26 pm, mahesh.nimbal...@gmail.com wrote:
> Yes it will work except one case and that is not acceptable. The case
> is, user can select whatever is the default date shown in the
[quoted text clipped - 111 lines]
>
> > > > > > > > > Thanks!
mahesh.nimbalkar@gmail.com - 31 May 2007 21:32 GMT
Al right. Can you please post some code sample how to hook key pressed
event for this DateTimePicker control?

> What you want to do is not so easy and maybe you should rethink the
> way you do it (showing the datetimepicker opened initially is not very
[quoted text clipped - 135 lines]
>
> > > > > > > > > > Thanks!
VisualHint - 31 May 2007 22:17 GMT
In the DropDown event handler:

hMonthCalendar = (IntPtr)SendMessage(dateTimePicker.Handle, 0x1008 /
*DTM_GETMONTHCAL*/, 0, 0);

You will find on CodeProject several articles about hooks. Here is
one: http://www.codeproject.com/csharp/globalhook.asp (don't know if
it's the best).

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 May 31, 4:32 pm, mahesh.nimbal...@gmail.com wrote:
> Al right. Can you please post some code sample how to hook key pressed
> event for this DateTimePicker control?
[quoted text clipped - 138 lines]
>
> > > > > > > > > > > Thanks!
mahesh.nimbalkar@gmail.com - 31 May 2007 22:42 GMT
Thank you!

> In the DropDown event handler:
>
[quoted text clipped - 156 lines]
>
> > > > > > > > > > > > Thanks!

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.