Pergunta

Microsoft's DateTimePicker common control shows ShortDate's according to the configured Locale settings. The customer's computer is configured with a 2-digit year ShortDateFormat (d/M/yy), so the DateTimePicker shows 2-digit years:

alt text

When the user puts focus in the year block of the datetime picker, Microsoft points out the issue, and shows the full 4-digit year:

alt text

But then the user, wanting to enter 1929 as a year, types a 2-digit year:

alt text

And then when they tab out they're confused when Windows interprets their 2-digit years as being between 1930 and 2029, and it is assumed to be 2029:

alt text

The customer has a global corporate policy in place which dictates that Windows regional settings be configured for 2-digit years.

So as a workaround i need to force every DateTimePicker control to use a custom date-format, using the handy DateTime_SetFormat macro:

DateTime_SetFormat(hwnd_DateOfEventPicker, "d/M/yyyy");

This helps, so that now the DateTimePicker now always shows a 4-digit year:

alt text

The problem is that the user can still type in an "invalid" 2-digit year:

alt text

Which Windows is still intpreting, according to the rules, as 2029:

alt text

i need the date-time picker to reject 2-digit years.

If this can't work, then i'm going to be forced to replace every DateTimePicker with 3 edit boxes:

22 6 29

Where i can color invalid numbers red, and point out the invalid data entry by the user.

How can i prevent the DateTimePicker from accept y2k bugs?

Nenhuma solução correta

Outras dicas

If you add the DTS_APPCANPARSE window style, you can handle the WM_NOTIFY: DTN_USERSTRING message and parse the string yourself

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top