Home Forums WinForms controls Xceed Grid for WinForms Decimals in NumericEditor

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16852 |

    How do you limit the number of decimals when using a NumericEditor on the grid?  I have tried a lot of method and still cannot only get 2 digits when editing (viewing is fine, just when editing).  Here is the latest that I have tried with no success.

     

                Dim nf As New System.Globalization.NumberFormatInfo
                nf.CurrencyDecimalDigits = 2
                nf.NumberDecimalDigits = 2

                Dim wnt As New Xceed.Editors.WinNumericTextBox
                wnt.EditFormatProvider = nf
                wnt.InputMode = Xceed.Editors.NumericInputModes.FreeText
                wnt.Decimals = 2
                Dim ne As New Xceed.Grid.Editors.NumericEditor(wnt)
                gcReceipts.Columns(“colReceipts_PaymentAmount”).CellEditorManager = ne
     

    Imported from legacy forums. Posted by Mitchel (had 1879 views)

    User (Old forums)
    Member
    Post count: 23064

    The Decimals property determines the maximum number of decimals the text can have for it to be validated, not a limit to the number of decimals that can be typed when editing.  What you need to do is to NOT set this property on the editor, and instead use the ValidatingText event on the TextBox of the editor, to ensure it does what you want.

    e.g. :

    //At form_load
          t_Column2.CellEditorManager.ActivatingControl += new CellEditorEventHandler(numericEditor_ActivatingControl);
          t_Column2.CellEditorManager.DeactivatingControl += new CellEditorEventHandler(numericEditor_DeactivatingControl);

    //Events handler
        private void numericEditor_ActivatingControl( object sender, CellEditorEventArgs e )
        {
          Xceed.Editors.WinNumericTextBox winNumericTextBox = e.Control as Xceed.Editors.WinNumericTextBox;

          winNumericTextBox.TextBoxArea.ValidatingText += new Xceed.Editors.ValidatingTextEventHandler( TextBoxArea_ValidatingText );
        }

        private void numericEditor_DeactivatingControl( object sender, CellEditorEventArgs e )
        {
          Xceed.Editors.WinNumericTextBox winNumericTextBox = e.Control as Xceed.Editors.WinNumericTextBox;

          winNumericTextBox.TextBoxArea.ValidatingText -= new Xceed.Editors.ValidatingTextEventHandler( TextBoxArea_ValidatingText );
        }

        private void TextBoxArea_ValidatingText( object sender, Xceed.Editors.ValidatingTextEventArgs e )
        {
          Xceed.Editors.NumericTextBoxArea numericTextBoxArea = sender as Xceed.Editors.NumericTextBoxArea;

          int decimalSeparatorIndex = e.EditText.IndexOf( ‘.’ );

          if( decimalSeparatorIndex != -1 )
          {
            string afterDecimalSeparator = e.EditText.Remove( 0, decimalSeparatorIndex + 1 );

            if( afterDecimalSeparator.Length > 2 )
              e.Valid = false;
          }

    Imported from legacy forums. Posted by André (had 1977 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.