Reputation: 2645
I am using a datetime picker in c# windows forms application.
How to set the the min time and max time ? I have a string "07:52:22" and I want to set this as the max or min time. How can I do this ?
DatetimePicker.MinDate.TimeOfDay = "07:52:22";
This is wrong but this is what I want.
Upvotes: 2
Views: 9211
Reputation: 649
DateTimePicker datePicker = new DateTimePicker;
dateTimePicker.MinDate = DateTime.Parse("7:52:22");
Upvotes: 3
Reputation: 942548
Right, not supported. You'll have to add the validation yourself with the ValueChanged event. You could just limit it like this:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) {
var max = new TimeSpan(7, 52, 22);
if (dateTimePicker1.Value.TimeOfDay >= max) {
dateTimePicker1.Value = dateTimePicker1.Value.Date + max;
}
}
Upvotes: 5