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

Entering decimals

1 Answer 59 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Daní
Top achievements
Rank 1
Daní asked on 07 Feb 2011, 10:24 AM
Hello,

Most of users using my application live in Spain, so thier culture is set to "ES". That means they are using "." for nuymber group separator and "." for number decimal separator.The issue appears when they are using the numeric pad, if they pressed the decimal Key (".") NumericUpDown control process it as a group separatos and not as a decimal separator. I can change the NumberFormatInfo settings in the application but I'd like they could keep visualizing numeric info in their culture format but being able to use the numeric pad for better productivity. I've tried to inherit from RadNumricUpDown control and override the OnKeyDown but I don't how to do else.

Please, help me!!

1 Answer, 1 is accepted

Sort by
0
Daní
Top achievements
Rank 1
answered on 07 Feb 2011, 11:22 AM
Hello,

I finally found a workaround inheriting from RadNumericUpDown. The key is holding a reference to the inner TextBox and overriding the OnKeyDown method. I paste the code here, maybe is useful to someone:
private TextBox _textBox;
 
public override void OnApplyTemplate()
{
    base.OnApplyTemplate();
    _textBox = GetTemplateChild("textbox") as TextBox;
}
 
protected override void OnKeyDown(KeyEventArgs e)
{
    if (e.Key == Key.Decimal)
    {
        e.Handled = true;
         if (_textBox != null)
         {
           switch (this.ValueFormat)
          {
               case Telerik.Windows.Controls.ValueFormat.Currency:
                    _textBox.Text += Thread.CurrentThread.CurrentUICulture.NumberFormat.CurrencyDecimalSeparator;
               break;
              default:
                  _textBox.Text += Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
               break;
             }
            _textBox.Select(_textBox.Text.Length, 1);
    }
     return;
            }
            base.OnKeyUp(e);
        }
Tags
NumericUpDown
Asked by
Daní
Top achievements
Rank 1
Answers by
Daní
Top achievements
Rank 1
Share this question
or