DateTimePicker fires DateChanged event when changing month

Windows exposes the events DropDown and CloseUp for this control. Between both you are navigating the calendar. To work around part of the issue we could cache the current value on DropDown, avoid firing “datechanged” while in this mode, return such cached value to the current value if the ESC key were pressed, consult if the cached value differs from the current value on the CloseUp event, and fire “DateChanged” ONLY in such case. The issues with Einhugur and Xojo are on their implementation because MS exposes enough properties and events to handle them. The double “datechanged” Xojo issues may be linked to some Xojo bug on how Xojo handles the BOTH MS events TextChanged and ValueChanged that this control exposes.

Hi @Gary_Smith

Ok, I can catch the DTN_DROPDOWN and DTN_CLOSEUP messages from the underlying native DTP control… so the DateChanged event is not fired when the user click on the arrow keys; but, as soon the user clicks on any of the month arrows, the control changes the displayed date to the 1st day from the new selected month (no DateChanged event fired).

In that case, the DateChanged event would be fired only when the dropdown menu (the calendar view) is closed OR the user selects a new date from the calendar view (the calendar view closes itself).

That can lead for example to the following scenario:

— The DateTimePicker control is set to display the date: 2021/4/2
— The user clicks on the calendar view.
— The user clicks on the right arrow to change to the “Next” month: 2021/5/2 will be displayed in the control.
— The user doesn’t select a new date and closes the Calendar menu.
— DateChanged is fired with the date value: 2021/5/2

Of course, if the user selects a date in the calendar… that will be the date passed in the DateChanged event.

That would work?

That will work for me. I would prefer that No date be selected or the original date used unless I click on a day after moving to a different month.
Thanks

I think that in case of a ESC key pressed, the value should return to the previous state before DTN_DROPDOWN and no DateChanged should fire.

1 Like