Disable multiple dates in datetimepicker winform c #

I need to disable some dates in DateTimePicker, is this possible? For example, I have a date range: {20/12/2014, 21/12/2014, 22/12/2014, 23/12/2014, 24/12/2014} I need to disable the middle one or the last one in other situations, can someone help me?

The lack of dateTimePicker1.MainDate and dateTimePicker1.MaxDate.

Thank.

+4
source share
2 answers

Starting with .Net 4, this is possible in WPF. You can then place WPF datepickerinside the Winforms application. Example (from MSDN) for disabling Saturday and Sunday:

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<DatePickerDateValidationErrorEventArgs>(DatePicker_DateValidationError);

MSDN: http://msdn.microsoft.com/en-us/library/k7z0zy8k%28v=vs.110%29.aspx

, Winforms. WPF Winforms.

MSDN WPF Winforms:

https://msdn.microsoft.com/en-us/library/ms751797(v=vs.100).aspx

+2
0

All Articles