How do I disable some dates on a DateTimePicker control?

14,597

Solution 1

Developer Express controls are usually very flexible and judging from this support article you can achieve what you want to do with their DateEdit control.

The control collection can be obtained from the following location: Over 60 Free Controls from DevExpress. (the free offer is no longer available)

Don't forget to read the EULA.

Solution 2

The ease with which you can do this will depend on the dates you want to restrict. For instance, if you all you want to do is specify a range of valid dates to pick, then you can use the MinDate and MaxDate properties to set the bounds. If however, you want to cherry pick certain days within a range (for instance, no weekends), there is no built in method for doing this.

You could either find a third party control with this functionality, or you could try to hack it a bit by adding an event handler to the ValueChanged event, and forcing the current date time to the last value (which you'd have to cache) if they user picked something that was illegal according to your business logic... but this is a less than ideal way to do it.

Share:
14,597
Aneef
Author by

Aneef

Updated on June 18, 2022

Comments

  • Aneef
    Aneef almost 2 years

    I was wondering is it possible to disable selected dates in a DateTimePicker, so that user cannot select them. i know its possible in web forms but in windows forms im unable to do this.how can i achieve this.

  • Aneef
    Aneef about 14 years
    I guess I'd go with devexpress
  • TaW
    TaW over 7 years
    I see no frre controls there, only trials.
  • João Angelo
    João Angelo over 7 years
    You're a few years too late, they seem to no longer offer those set of free controls. I'll update the answer.