Click here to Skip to main content
16,016,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to have a DateTimePicker on a WinForm where the user can enter the date from the keypad?

What I have tried:

Not finding anything on the web about this.
Posted
Updated 15-Jul-23 3:20am
Comments
Richard MacCutchan 15-Jul-23 8:44am    
It depends on exactly how you want to set it. Maybe you could provide more details on exactly what you are trying to achieve.

1 solution

Yes - the standard "drop on the form" version does, you just have to know how.

Drop a DTP on your form, and run your code.
Tab (or click) to the DTP and the "Day of Month" will be highlighted.
Type date: "24-2-59" (in UK Culture) and it'll be set to "24th February, 1959". (You can use "/" or "-" interchangeably.)
 
Share this answer
 
Comments
MIDCOPC 18-Jul-23 7:34am    
This solution will work as long as there is an existing date in the DTP. When I open the winform, the date is blank.
OriginalGriff 18-Jul-23 9:53am    
Not on my system: if I drop a DTP on a form, it starts at today's date ... which makes sense, since the whole idea of a DTP is that it always holds a valid DateTime in it's Value property.
MIDCOPC 21-Jul-23 9:32am    
We set custom format on the DTP to " ". In our environment, we schedule appointments. If the DPT shows a date, say today's date, we can't trust our users to change the date of the appointment, so we have it blank when the form.
OriginalGriff 22-Jul-23 4:11am    
You need to tell us these things! :D

There doesn't seem to be a "nice" way to do this, and it seems that the custom format is the problem - if you set it to space then the edit boxes the user needs aren't there even if you open the calendar with the arrow. I'd just set a default date to a silly value - "1st Jan 2001" maybe - and check it as part of my input verification process (and when they try to tab or click away from the DTP. Maybe paint it red as well to show it needs to be corrected (and back to black when it validates).

Having a blank box doesn't encourage the average user to do anything useful with it and can frustrate them a lot when they can't click into it or visibly tab in either.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900