Entering decimals

2 posts, 0 answers
  1. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 07 Feb 2011 Link to this post

    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!!
  2. Daní
    Daní avatar
    303 posts
    Member since:
    Feb 2008

    Posted 07 Feb 2011 Link to this post

    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);
            }
  3. DevCraft banner
Back to Top