This question already has an answer here:
I need to disable some dates into DateTimePicker, is it possible? For example, I have a dates range: { 20/12/2014, 21/12/2014, 22/12/2014, 23/12/2014, 24/12/2014 } I need to disable the midle one or in others situations the last one, can anybody help me?
The dateTimePicker1.MainDate and dateTimePicker1.MaxDate is not enough.
Thank you.
Starting from .Net 4 it is possible in WPF. You can then host the WPF datepicker
inside a Winforms app. An example (from MSDN) to disable Saturdays and Sundays:
DatePicker datePickerWithBlackoutDates = new DatePicker(); datePickerWithBlackoutDates.DisplayDateStart = new DateTime(2009, 8, 1); datePickerWithBlackoutDates.DisplayDateEnd = new DateTime(2009, 8, 31); datePickerWithBlackoutDates.SelectedDate = new DateTime(2009, 8, 10); datePickerWithBlackoutDates.BlackoutDates.Add( new CalendarDateRange(new DateTime(2009, 8, 1), new DateTime(2009, 8, 2))); datePickerWithBlackoutDates.BlackoutDates.Add( new CalendarDateRange(new DateTime(2009, 8, 8), new DateTime(2009, 8, 9))); datePickerWithBlackoutDates.BlackoutDates.Add( new CalendarDateRange(new DateTime(2009, 8, 15), new DateTime(2009, 8, 16))); datePickerWithBlackoutDates.BlackoutDates.Add( new CalendarDateRange(new DateTime(2009, 8, 22), new DateTime(2009, 8, 23))); datePickerWithBlackoutDates.BlackoutDates.Add( new CalendarDateRange(new DateTime(2009, 8, 29), new DateTime(2009, 8, 30))); datePickerWithBlackoutDates.DateValidationError += new EventHandler(DatePicker_DateValidationError);
More details on MSDN: http://msdn.microsoft.com/en-us/library/k7z0zy8k%28v=vs.110%29.aspx
I haven't seen anything similar that would be specifically for Winforms though. As a workaround you can port this WPF component into Winforms app.
Here's MSDN resource on interopeartion of WPF and Winforms:
https://msdn.microsoft.com/en-us/library/ms751797(v=vs.100).aspx
You can specify a max date, but you cannot selectively disable arbitrary dates in the valid range.
Please see How do I disable some dates on a DateTimePicker control?