Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

How to validate datetime picker, here i want show date only in datetime picker based on month, the total 12 month is available on another ComboBox control, so which month user choose i want to show that month date only in datetimepicker(windows application)

how to do this,

Thanks...
Posted
Comments
Sinisa Hajnal 26-Mar-15 2:56am    
You set minumum and maximum date based on the selected month.
prasanna.raj 26-Mar-15 3:11am    
oh k just i ll try...
prasanna.raj 26-Mar-15 9:18am    
ice it working fine and if i change month it showing error, how to change month in datetimepicker based on combobox.

1 solution

You don't "validate" a DateTimePicker - instead you use the MinDate[^] and MaxDate[^] properties to restrict the range that it permits and it will validate them itself.

So when you handle the ComboBox changed event, set the MinDate to teh first of that month, and the MaxDate to the last day of the month (Which is simple: Use DateTime.AddMonths[^] to add +1 month, then DateTime.AddDays[^] to add -1 days to get you to the last day of the month you want)
 
Share this answer
 
Comments
prasanna.raj 26-Mar-15 3:11am    
oh k just i ll try...
prasanna.raj 26-Mar-15 9:17am    
nice it working fine and if i change month it showing error, how to change month in datetimepicker based on combobox.

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