Can't change AM/PM from keyboard

4 posts, 0 answers
  1. Davide
    Davide avatar
    17 posts
    Member since:
    Mar 2013

    Posted 02 Oct 2014 Link to this post

    I'm trying to use the RadMaskedDateTimeInput control, using a mask of "g", which provides date and time input with the AM/PM indicator. The AM/PM indicator can be changed using the up/down arrows when SpinMode is enabled but there is no way to change the AM/PM value using the keyboard. Do you have any solution or it is impossible for this component to do this?

    Thx in advance

    Davide
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 06 Oct 2014 Link to this post

    Hi,

    Could you please clarify what you have in mind when you say:"The AM/PM indicator can be changed using the up/down arrows when SpinMode is enabled"? Which arrows you refer to?

    Also, you are allowed to use the arrow keys of the keyboard to change the AP/PM selector. You can see this behavior in our QSF demo after changing the Mask to "g".

    Regards,
    Pavel R. Pavlov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Davide
    Davide avatar
    17 posts
    Member since:
    Mar 2013

    Posted 06 Oct 2014 in reply to Pavel R. Pavlov Link to this post

    Hi Pavel ... 

    In the RadMaskedDateTimeInput i'm displaying only the time as shown in the image 

    For the hours, minutes and seconds i can edit them  but this cannot be done for the AM/PM value. I was asking if there is any way to be able to set this value from the keyboard typing A o P

    Thx in advance

    Davide




  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 07 Oct 2014 Link to this post

    Hi Davide,

    In order to change the AM with PM when the "p" key is pressed you can do these steps:
    1. Subscribe to the KeyDown event of the control
    2. Add 12 hours to the current Value
    If you need the opposite, you can subtract 12 hours when the "a" key is pressed.

    You can use this code as starting point:

    private void RadMaskedDateTimeInput_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.A)
        {
            DateTime fullValue = (DateTime)(sender as RadMaskedDateTimeInput).Value;
            if (fullValue.Hour >= 12)
            {
                (sender as RadMaskedDateTimeInput).Value = new DateTime(fullValue.Year, fullValue.Month, fullValue.Day, fullValue.Hour - 12, fullValue.Minute, fullValue.Second);
            }
        }
        if (e.Key == Key.P)
        {
            DateTime fullValue = (DateTime)(sender as RadMaskedDateTimeInput).Value;
            if (fullValue.Hour <= 12)
            {
                (sender as RadMaskedDateTimeInput).Value = new DateTime(fullValue.Year, fullValue.Month, fullValue.Day, fullValue.Hour + 12, fullValue.Minute, fullValue.Second);
            }
        }
    }


    Regards,
    Pavel R. Pavlov
    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.

     
Back to Top