Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restrict dates in 'datetimepicker' in C#

A feature of a forms based application I am developing allows the user to search through a history of records.

The user can search by name, by number, and between dates, and populate the results in a datagridview control.

Here is the form:

However, as the form will be used to search for previous records. The ability for the user to select future dates is not required.

Is there a way to prevent the user from selecting future dates, or even grey the future dates out?

like image 460
Jordan-C Avatar asked Feb 16 '26 13:02

Jordan-C


2 Answers

You can try with code based on MaxDate property

yourControl.MaxDate = DateTime.Today;

Link : http://msdn.microsoft.com/fr-fr/library/system.windows.forms.datetimepicker.maxdate.aspx

like image 126
Aghilas Yakoub Avatar answered Feb 19 '26 02:02

Aghilas Yakoub


Please try:

dateTimePicker.MaxDate = DateTime.Now;
like image 36
petro.sidlovskyy Avatar answered Feb 19 '26 03:02

petro.sidlovskyy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!