This is a migrated thread and some comments may be shown as answers.

Formatting RadDateTimePicker

6 Answers 763 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Johannes asked on 13 Mar 2015, 10:54 AM
I am very confused about RadDateTimePickers formatting behavior. When we set DateSelectionMode to Year, why does it still create a complete date with the selected year but also with day/month from todays date?! This makes absolutely no sense to me. It should display the year only cause that's what my users select - a year, not a full date.

Searching the forums I found several posts showing that we can set a new Culture to define custom ShortDatePattern and LongDatePattern. I did this and changed both formats to "yyyy". Now the control is displaying the year only (yeeha!) but it seems this format is not correct date Format for RadDateTimePickers parser. Checking the ParseDateTime event I can see that e.IsParsingSuccessful is always false now.

So here's the question: How to select a year (yyyy) or month & year (mm/yyyy), display exactly what I've selected in the control's input box AND parse this value as a correct date in code behind?

6 Answers, 1 is accepted

Sort by
0
Johannes
Top achievements
Rank 1
answered on 13 Mar 2015, 12:47 PM
This can be reproduced with your XAML SDK solution "DateTimePicker_WPF" and project "StringFormatMVVM_WPF".

Simply set ShortDatePattern from "dd.MM.yy" to "yyyy". Selecting a year from DropDown is still possible but entering a year manually (and that's what our users will do) results in an error.
0
Nasko
Telerik team
answered on 17 Mar 2015, 03:04 PM
Hello Johannes,

When displaying and selecting only years in RadDateTimePicker the ParseExact property needs to be set to True:
<telerik:RadDatePicker ParseExact="True" x:Name="Picker" DateSelectionMode="Year" />

Hopes this helps.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Johannes
Top achievements
Rank 1
answered on 18 Mar 2015, 08:52 AM
Thanks for your reply but this does not help.

When I enter 2 digits "15" the fields value becomes "2015" - that's nice. But when I enter 4 digits the ToolTip is displaying "Error". On LostFocus validation comes into place and the field becomes empty. It doesn't matter if ParseExcat is true or false - you can not enter a year with 4 digits.
0
Nasko
Telerik team
answered on 18 Mar 2015, 10:43 AM
Hi Johannes,

We were not able to observe the described behavior after setting ParseExact = "True" - please, check the attached video and let me know if there is something we missed. Also, please notice that if you didn't set the InputMode property to "DatePicker" and enter just an year without a time the parsing won't work again. However, if that is not the case please capture and send us a video with the observed by you behavior - it will be of great help in our further investigation?

We're looking forward to hearing from you.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Johannes
Top achievements
Rank 1
answered on 18 Mar 2015, 12:56 PM
Thanks for your video. It seems that this is working as long as I set ShortDatePattern and LongDataPattern both to "yyyy".

Now please take a look at my Video (see link below). My target is to have ShortDatePattern "yy" and LongDatePattern "yyyy". It looks like RadDatePicker is always using ShortDatePattern for parsing, no matter if DisplayFormat is Short or Long. Shouldn't the parser use LongDatePattern if DisplayFormat is Long and ShortDatePattern if DisplayFormat is Short?

http://www.screencast.com/t/gZ7ByzsqB7
0
Nasko
Telerik team
answered on 19 Mar 2015, 07:49 AM
Hello Johannes,

The observed by you behavior of RadDateTimePicker is an expected one. The control parses the entered value only by the set ShortDatePatern - if you try to enter the date in the format set to LongDatePattern, it will not be parsed. The date could not be parsed by both ShortDatePattern and LongDatePattern - you could use the LongDatePattern in order to visualize the date differently using the DisplayFormat property but if you try to modify it that won't be accepted.

However, what we could suggest you for you scenario is to implement a custom parsing which will accept both formats. Please, check this article from our help documentation that will provide you a detailed information how to achieve this:
http://docs.telerik.com/devtools/wpf/controls/raddatetimepicker/how-to/implement-custom-parsing.html

Hopes this information will help you.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
DateTimePicker
Asked by
Johannes
Top achievements
Rank 1
Answers by
Johannes
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or