RadDateTimePicker How to set DateTimeText when DateTime is invalid

1 Answer 70 Views
DateTimePicker
Hugo
Top achievements
Rank 1
Hugo asked on 12 Jul 2023, 09:28 AM

Hi


I use the RadDateTimePicker and have a button ("Next"):

When now the user changes the date/time value to an invalid date/time an error is shown:

When the user clicks on the "Next" button the DateTimeText disapears and is empty and an error is schown:

My Question:
Is it possible to set the DateTimeText to the previous wrong formatted date/time (120000000000.07.23 08:49) like this ? 

I have tried to overload the method  OnParseDateTime and set the CurrentDateTimeText but it's not working.

1 Answer, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 13 Jul 2023, 11:19 AM

Hello Hugo,

For this to be possible you can update the CurrentDateTimeText property of RadDateTimePicker in the LostFocus event handler.

private void myDatePicker_LostFocus(object sender, RoutedEventArgs e)
{
	myDatePicker.CurrentDateTimeText = lastInput;
}

I created the lastInput field, representing the last entered text. Then through the ParseDateTimeValue method I saved this text to the field.

private void myDatePicker_ParseDateTimeValue(object sender, ParseDateTimeEventArgs args)
{
	lastInput = args.TextToParse;
}

You can check my simple solution how to make this. Also, you can take a look at the How to implement custom parsing article that describes the ParseDateTimeValue event.

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Hugo
Top achievements
Rank 1
commented on 17 Jul 2023, 11:56 AM

Hi Dinko

Thank you for the answer.
It solved my problem perfectly!

 

Regards,
Hugo

Tags
DateTimePicker
Asked by
Hugo
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Share this question
or