By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,633 Members | 1,867 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,633 IT Pros & Developers. It's quick & easy.

DateTimePicker Bug?

P: n/a

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.)

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,

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

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,
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
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

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
Nov 21 '05 #2

P: n/a
Thank you very much for your almost immediate response. Your quite
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
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

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
it would 'out of the box'.


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.