PC Review


Reply
Thread Tools Rate Thread

DateTimePicker Bug?

 
 
Chris Fairman
Guest
Posts: n/a
 
      6th Apr 2005
NG,

Maybe I'm missing a key step, but it seems when typing dates into a
DateTimePicker control (format = 'Short'), the controls' .text property is
not updated until the control losses focus.

I'm handling an <enter> key event on a DateTimePicker control.
Essentially I want to give a user the ability to type a date in the
DTP, and press <enter> and have a DataGrid populate with user
supplied data from the DTP control.

I can get the DataGrid to populate, but the DTP control isn't updated
with the key strokes supplied by the user, unless:
1. The control looses focus
2. You click into another field within the control itself. (If you were
changing the 'day' value of the control, clicking in the month or year
fields will update the 'day' value in the .text property.)

So...
If the DTP control reads [02/15/2005] and I click on the 15, type 20 and
press <enter> the .text value for the DTP control still reads 02/15/2005,
instead of 02/20/2005. Unless... (as stated above -control losses focus,
etc...)

I've recreated the DTP controls just in case, but getting the same
behavior.

I've tried invoking both .update() and .refresh() DTP methods
before reading in the .text value, but none of these methods are helping.
The .text value and the actual text of the DTP are never equivalent
(Unless -as stated above -control losses focus, etc...)

Hope all that made sense to somebody.

Thanks in Advance,
-Chris
 
Reply With Quote
 
 
 
 
Oenone
Guest
Posts: n/a
 
      7th Apr 2005
Chris Fairman wrote:
> Maybe I'm missing a key step, but it seems when typing dates into a
> DateTimePicker control (format = 'Short'), the controls' .text
> property is not updated until the control losses focus.


I've tried and tried to recreate this, but I haven't been able to. Every
time I query it, it returns the newly-entered date.

I added a DateTimePicker control to a form and changed its Format to Short.

I then first tried adding a command button and set it as the AcceptButton
for the form. In the click event I put this code:

MsgBox(DateTimePicker1.Text & " : " & DateTimePicker1.Value)

No matter what I did, the correct date was always displayed when I pressed
Enter.

I then took away the command button and put the same MsgBox into the
DatePicker's KeyDown event for when the user pressed Enter:

If e.KeyCode = Keys.Enter Then
MsgBox(DateTimePicker1.Text & " : " & DateTimePicker1.Value)
e.Handled = True
End If

This worked fine too.

Are you handling the enter key differently in your project? Can you recreate
the problem in a standalone project?

The only thing I found similar to your description was if I typed a
single-digit value into a two digit field. For example, if I opened the form
defaulting to today's date, and typed just "2" into the month field, the
MsgBox would still display 2005-04-07 (though the display in the control now
correctly showed February). OK-ing the MsgBox and pressing Enter again
returned the expected date of 2005-02-07. If I type a two-digit day or
month, this doesn't occur though.

I found I could work around this by simply telling the form to set focus to
itself before the MsgBox statement (Me.Focus). This then produced the
correct date in the MsgBox, and still left the focus in the datepicker
control. Perhaps you might be able to try this in your code?

--

(O) e n o n e


 
Reply With Quote
 
Chris Fairman
Guest
Posts: n/a
 
      7th Apr 2005
Thank you very much for your almost immediate response. Your quite
right,
it seems this behavior is only exhibited when entering partial days,
months or years.

I guess I failed to notice that. All my test cases where with single
digits (even though my posted example used double digits -sorry!)...

Programmaticly changing focus to the form, and back to the object
works,
but that seems like an ugly workaround for what might be considered
expected/basic behavior.

This along with how the cursor is not moved to a day or year after
typing in a month or day makes me think the dot-net DTP could be a bit
more polished.

I guess I'm stuck with it, maybe they will spruce it up for dot-net
v.2.

Anyhow thank you for taking the time to look at it, moving the focus
around to other objects and back again makes it behave like I was
hoping
it would 'out of the box'.

-Chris

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
datetimepicker enrico via DotNetMonster.com Microsoft VB .NET 0 12th Mar 2008 05:45 AM
DateTimePicker help please =?Utf-8?B?VG9tIFJhaGF2?= Microsoft Dot NET 0 14th Feb 2005 12:29 PM
DateTimePicker =?Utf-8?B?UmF0?= Microsoft Dot NET 1 19th Mar 2004 12:53 PM
Datetimepicker =?Utf-8?B?QXZuaQ==?= Microsoft Dot NET 5 26th Jan 2004 02:12 PM
DateTimePicker Gary Miller Microsoft C# .NET 0 14th Sep 2003 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:58 AM.