NumericUpDown accept $ sign for Numeric ValueFormat

4 posts, 0 answers
  1. Susanto
    Susanto avatar
    2 posts
    Member since:
    May 2012

    Posted 21 May 2012 Link to this post

    Hi,

    It seems that when using a 'Numeric' ValueFormat property for NumericUpDown control, it still accept '$' sign key on the UI and disappear after clicking either enter, escape or tab.

    Is there anyway to intercept '$' sign and remove it? Otherwise, this may confuse the end user.
    I have tried to use Key_Down and TextInput event but was unable to fix it.

    Steps to reproduce:
    1. Type some value. For example, 23.
    2. Type in dollar sign at the beginning. For example, $23.
    3. Continue type in the value. For example, $23.5123.
    4. Click either enter, escape or tab.

    OR
    1. Type some value. For example, 23.
    2. Type in dollar sign at the end. For example, 23$. At this point, user is disallow to add more numbers.
    3. Click either enter, escape or tab.

    Thanks,

    Santo
  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 23 May 2012 Link to this post

    Hi,

    You want to restrict the user entering only numbers - is that correct? If so, hooking to the Key_Down event should do the trick - when the typed symbol is $ you could reset the Text property of the Numeric.
    Could you please share with us what kind of difficulties do you experience?

    All the best,
    Konstantina
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Susanto
    Susanto avatar
    2 posts
    Member since:
    May 2012

    Posted 23 May 2012 Link to this post

    Hi Konstantina,

    The difficulty I had was that when pressing shift + 4, the event I got was the Key.Shift but not the $ sign key which I don't think is mapped in the Key enumeration too.

    Using TextInput didn't fire up the event on text changed but I think only when finished editing.


    Thanks,

    Santo
  5. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 25 May 2012 Link to this post

    Hi Susanto,

    I was able to produce the effect you're looking for. Here' what I did.

    <telerik:RadNumericUpDown x:Name="usdNumeric"
                                          Value="{Binding USDAmount, Mode=TwoWay}"
                                          Grid.Row="1"
                                          Grid.Column="2"
                                          Minimum="1"
                                          ValueFormat="Currency"
                                          HorizontalAlignment="Stretch"
                                          VerticalAlignment="Center"
                                          KeyUp="usdNumeric_KeyUp"
                                          MinWidth="113"/>


    If you use the KeyDown event, the shift key would cause the event to trigger too soon and you wouldnt be able to check for the $ character. Instead, use KeyUp. It waits until the user releases the number 4 key before firing.

    Summary: In order for the user to be able enter the $ character they must hold down the shift key through the whole keypress (Silverlight waits for the end of the 2nd keypress while holding the shift key before triggering a KeyUp event), which is what you need in order to check for the $ character in your event.

    Good Luck!
    Lancelot
Back to Top