Hello
I have DateTimePicker with date in format dd-MM-yyyy. Initial date in this control is 01-02-2020. I want to write new date (31-01-2020) in MaskEdeditBox but after set day cursor correctly move to month section and day section changes walues to '01'. Could I define other behavior for this situations? For example when currently set month not has enough days month automatically decreases by 1.
Best wishes
3 Answers, 1 is accepted
Hello Zygmunt,
By design, RadDateTimePicker tries to handle the user's input while he is typing and it strives to keep a valid DateTime value. 31/02/2020 is not a valid DateTime and the user won't be allowed to enter it.
I would recommend you to use the MaskType.FreeFormDateTime which I believe is a suitable approach for your scenario. However, have in mind that while RadDateTimePicker is focused the user is allowed to enter the date in any format. But once the RadDateTimePicker control loses focus, the value will be parsed to a valid DateTime: https://docs.telerik.com/devtools/winforms/controls/editors/datetimepicker/free-form-date-time-parsing
Тhe format should be set in this way:
this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.MaskType = MaskType.FreeFormDateTime;
this.radDateTimePicker1.Format = DateTimePickerFormat.Custom;
this.radDateTimePicker1.CustomFormat = "dd-MM-yyyy";
Note that only the FreeFormDateTime mask will satisfy your request because other types validate on every key press and this behavior cannot be avoided.
Regards,
Peter
Progress Telerik
Hi Zygmunt,
We can offer only the FreeFormDateTime mask format (see the attached screenshot) for this case because other DateTime formats validate the date on every keypress and this behavior cannot be avoided.
Please, refer to the attached sample project.
Regards,
Peter
Progress Telerik