Custom format DatePicker issue

4 posts, 0 answers
  1. Anita
    Anita avatar
    2 posts
    Member since:
    Jul 2015

    Posted 13 Jul 2015 Link to this post

    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.

     

  2. Geri
    Admin
    Geri avatar
    60 posts

    Posted 15 Jul 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anita
    Anita avatar
    2 posts
    Member since:
    Jul 2015

    Posted 15 Jul 2015 in reply to Geri Link to this post

    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. 

  5. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 17 Jul 2015 Link to this post

    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
Back to Top