Search code examples
c#winformsdatetimepicker

Datetimepicker block earlier date


I have two dateTimePicker and I would like to know if it is possible to do something like this. I choose date at first one and in second one it will automatically block possibility of choosing earlier date than the first one? If so, how can I achieve it?


Solution

  • You can handle the first DateTimePicker's ValueChanged event and set the second DateTimePicker's MinDate property there.

    private void firstDateTimePicker_ValueChanged(object sender, EventArgs e)
    {
        //add code to validate selected value (handle errors etc...)
        //...        
    
        secondDateTimePicker.MinDate = firstDateTimePicker.Value;
    }