Unplanned
Last Updated: 16 Jul 2025 13:23 by ADMIN
Jackson
Created on: 16 Jul 2025 13:14
Category: DateTimePicker
Type: Bug Report
0
RadDateTimePicker: When the hour part is 12, clicking the A key does not change the daytime part from PM->AM
In this scenario, the RadDateTimePicker control is set in the following way:

public Form1() { InitializeComponent(); this.radDateTimePicker1.MaskProviderCreated += RadDateTimePicker1_MaskProviderCreated; this.radDateTimePicker1.DateTimePickerElement.ShowCurrentTime = false; this.radDateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom; this.radDateTimePicker1.Culture = new System.Globalization.CultureInfo("en-US"); this.radDateTimePicker1.CustomFormat = "hh:mm:ss tt";
this.radDateTimePicker1.Value = new System.DateTime(2025, 6, 12, 12, 4, 34, 562); }

When we focus the text editor daytime part(last part) we can't change it from PM to AM by clicking the A key. However, the opposite way is working. When we have AM and clicking the P key will change it to PM.
1 comment
ADMIN
Dinko | Tech Support Engineer
Posted on: 16 Jul 2025 13:23

Hello Jackson,

Thank you for reporting this. Here is a possible workaround. In a few words, we need to override the HandleAmPmKeyPress method in the MaskDateTimeProvider of the control and handle this scenario.

public Form1()
{
    InitializeComponent();
    this.radDateTimePicker1.MaskProviderCreated += RadDateTimePicker1_MaskProviderCreated;
    this.radDateTimePicker1.DateTimePickerElement.ShowCurrentTime = false;
    this.radDateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
    this.radDateTimePicker1.Culture = new System.Globalization.CultureInfo("en-US");
    this.radDateTimePicker1.CustomFormat = "hh:mm:ss tt";
}

private void RadDateTimePicker1_MaskProviderCreated(object sender, EventArgs e)
{
    this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.Provider = new CustomProvider(this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.Mask, this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.Culture, this.radDateTimePicker1.DateTimePickerElement.TextBoxElement);
}

public class CustomProvider : MaskDateTimeProvider
{
    public CustomProvider(string mask, CultureInfo culture, RadMaskedEditBoxElement owner) : base(mask, culture, owner)
    {
    }
    protected override void HandleAmPmKeyPress(KeyPressEventArgs e)
    {
        // base.HandleAmPmKeyPress(e);
        char am = this.Culture.DateTimeFormat.AMDesignator.ToLower()[0];
        char pm = this.Culture.DateTimeFormat.PMDesignator.ToLower()[0];

        var field = this.GetType().BaseType.GetField("value", BindingFlags.Instance |
                        BindingFlags.NonPublic |
                        BindingFlags.DeclaredOnly);
        DateTime valueObjectCache = (DateTime)field.GetValue(this);

        if (am == char.ToLower(e.KeyChar))
        {
            if (valueObjectCache.Hour >= 12)
            {
                this.Value = valueObjectCache.AddHours(-12);
            }
        }
        else if (pm == char.ToLower(e.KeyChar))
        {
            if (valueObjectCache.Hour < 12)
            {
                this.Value = valueObjectCache.AddHours(12);
            }
        }
    }
}

Regards,
Dinko | Tech Support Engineer
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.