Michal_LFC
Michal_LFC

Reputation: 599

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?

Upvotes: 2

Views: 1611

Answers (2)

Marcus
Marcus

Reputation: 8659

Use the ValueChanged event of the the first dateTimePicker and set the MinDate of dateTimePicker2 to the value of the dateTimePicker1.

dateTimePicker2.MinDate = dateTimePicker1.Value;

Upvotes: 2

keyboardP
keyboardP

Reputation: 69372

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;
}

Upvotes: 3

Related Questions