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

Custom format DatePicker issue

3 Answers 178 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Anita
Top achievements
Rank 1
Anita asked on 13 Jul 2015, 07:21 PM

I have followed this guide line for custom date format dd mmm yyyy (http://docs.telerik.com/devtools/wpf/controls/raddatetimepicker/features/formatting.html#changing-the-display-format)

 But it affected date resolution when I manual enter date. Please refer attached screenshot.

 

3 Answers, 1 is accepted

Sort by
0
Geri
Telerik team
answered on 15 Jul 2015, 12:31 PM
Hello Anita,

When you define a custom format of type "dd MMM yyyy", the month should be written with letters, instead of digits, otherwise it cannot be parsed.

However if you need to implement custom parsing logic, you can do it simply by hooking to the ParseDateTimeValue event of the control. Guidance on how to do this, you can find in this article:

http://docs.telerik.com/devtools/wpf/controls/raddatetimepicker/how-to/implement-custom-parsing.html

Hope this helps.

Regards,
Geri
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Anita
Top achievements
Rank 1
answered on 15 Jul 2015, 02:38 PM

Does it mean for custom display format, I have to override parsing logic?

Here I am trying to change display format but I still want to get whatever default parsing behavior available in control. 

0
Rosi
Telerik team
answered on 17 Jul 2015, 03:04 PM
Hi Anita,

To achieve what you described in your first post you can just hook on the ParseDateTimeValue event and change the parsing logic only for a specific scenario as shown below. In this case all other cases will be handled by the default parsing logic of the control.

private void datePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
{
    string input = args.TextToParse.ToLower();
    string[] splitedInput = input.Split(new Char[] { ' ', ',', ':', '/' });
    DateTime res = new DateTime(1, 1, 1);
    if (input == "9/14/2015")
    {
        switch (splitedInput.Length)
        {
            case 1: args.IsParsingSuccessful = true;
                res = new DateTime(DateTime.Now.Year, DateTime.Now.Month, Convert.ToInt32(splitedInput[1])).Date;
                break;
            case 2: args.IsParsingSuccessful = true;
                res = new DateTime(DateTime.Now.Year, Convert.ToInt32(splitedInput[0]), Convert.ToInt32(splitedInput[1])).Date;
                break;
            case 3: args.IsParsingSuccessful = true;
                res = new DateTime(Convert.ToInt32(splitedInput[2]), Convert.ToInt32(splitedInput[0]), Convert.ToInt32(splitedInput[1])).Date;
                break;
            default: args.IsParsingSuccessful = true;
                break;
        }
    }
    args.Result = res;
}

In order to simplify the example, the input is hard-coded, but you can modify the logic according to your needs.

Hope this helps.

Regards,
Rosi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DatePicker
Asked by
Anita
Top achievements
Rank 1
Answers by
Geri
Telerik team
Anita
Top achievements
Rank 1
Rosi
Telerik team
Share this question
or