This is a migrated thread and some comments may be shown as answers.

NumericUpDown accept $ sign for Numeric ValueFormat

3 Answers 148 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Susanto
Top achievements
Rank 1
Susanto asked on 21 May 2012, 08:24 AM
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

3 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 23 May 2012, 02:14 PM
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 >>
0
Susanto
Top achievements
Rank 1
answered on 24 May 2012, 12:44 AM
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
0
Lancelot
Top achievements
Rank 1
answered on 25 May 2012, 09:53 PM
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
Tags
NumericUpDown
Asked by
Susanto
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Susanto
Top achievements
Rank 1
Lancelot
Top achievements
Rank 1
Share this question
or