Prevent NumericUpDown from activating the edit box when I hit +/-

1 Answer 44 Views
NumericUpDown
Joe
Top achievements
Rank 1
Joe asked on 08 May 2024, 05:54 PM
I have a simple NumericUpDown control showing milliseconds.  I use a 'ms' custom unit to show alongside the number. 

<tk:RadNumericUpDown  Width="150"  Height="50"
    Value="{Binding Exposure}"
    IsInteger="True"
    CustomUnit="ms"/>

It looks good but as soon as hit the + or - key, the 'ms' disappears and I have just a number.  This is because hitting +/- gives keyboard focus to the edit box -- activates the cursor in there and all that.    Once I click somewhere else focus leaves the edit box, the 'ms' re-appears.

Is there a property or some simple way that would let me prevent this behavior?   I want +/- to just change the number without grabbing the keyboard focus.  

Note that I do still want the number to be user-editable if they actually go to the trouble of clicking directly in the edit box itself.  I just want to stop +/- from doing that for me.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 09 May 2024, 08:26 AM

Hi Joe,

You can create a custom control and override the FormatEdit method. Here is an example: 

public class MyMupDown : RadNumericUpDown
{
    public override string FormatEdit()
    {
        var value = base.FormatEdit();
        return value + "ms";
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
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.

Joe
Top achievements
Rank 1
commented on 16 May 2024, 09:35 PM

Hi Dimitar,

Thank you for the answer.  Unfortunately this does not quite get me there. 

While this fix does prevent +/- from putting focus in the edit box, unfortunately it also prevents me from ever using the edit box again.  Now even if I click in there and try to type a number, the keys are ignored.
Dimitar
Telerik team
commented on 20 May 2024, 08:48 AM

Hi Joe, 

It works on my side. I have attached my project and a small video that shows this. 

Let me know what I am missing.

Tags
NumericUpDown
Asked by
Joe
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or