473,890 Members | 1,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTimePicker Bug?


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
2 3393
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(DateTime Picker1.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(DateTime Picker1.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
by: Jacek Jurkowski | last post by:
.... the minimum date of DateTimePicker is 1753-01-01. How to make DateTime to do not show nothing in its text if this date is the value? I have a form with a field LastLogonDate. If user hasn't logon yet this date should be empty but when binding a property to the DateTimePicker value it always shows value parsed prom property which is 1753-01-01. How to make an "empty" or "not set" date bindable to a value property of DateTimePicker?
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from the DateTimePicker, since the default is shown. My problem is, if the user does not choose a value from the DateTimePicker (because using the default is good enough), then during database update, the date value is not saved to the database; while if...
by: Charlie | last post by:
In the top portion of the DateTimePicker, where the value of the date is displayed, how can I detect whether the month or day or year is currently focused, or, if ShowCheckBox = True, whether the checkbox is focused?
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a datetimepicker ("Value") for it's "DateTime" property. The DateTimePicker.Visible value is set to...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.