Home Forums WinForms controls Xceed Grid for WinForms Trailing zeros

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

    Hello

     I’m displaying a decimal(38, 20) column from SQL Server database using Xceed Grid Control. I don’t want showing trailing zeros after decimal point, so I set FormatSpecifier property to “#.####################” and all works. But it still shows trailing zeros when I begin editing column. Any ideas on solving this problem?

     

    Thanks in advance!

    Imported from legacy forums. Posted by Nazar (had 917 views)

    Xceed Support
    Member
    Post count: 5658

    To avoid showing the trailing zeroes in edition mode:

    you need to assign a numeric editor to your cells. You create this editor using a WinNumericTextbox in the constructor, which has a displayformatspecifier that can be set. Find below a code snippet on how to implement:

          WinNumericTextBox template = new WinNumericTextBox();
          template.DisplayFormatSpecifier = “#.####################”;
          NumericEditor numericEditor = new NumericEditor( template );
          CellEditorManager cellEditorManager = numericEditor;

          gridControl1.Columns[ “FormatedColumn” ].CellEditorManager = cellEditorManager;



    Imported from legacy forums. Posted by Mohamed [Xceed] (had 414 views)

    User (Old forums)
    Member
    Post count: 23064

    It does not help! I still get many zeros…

    How to reproduce it:
     
    I have DataSet with DataTable with only one field (called Test) which has System.Decimal data type.

    Then I bind grid to this DataTable in designer.

    Then I do the folowing in code:

            private void Form1_Load(object sender, EventArgs e)
            {
                Xceed.Editors.WinNumericTextBox EditorTemplate = new Xceed.Editors.WinNumericTextBox();
                EditorTemplate.DisplayFormatSpecifier = “#.####################”;
                colTest.CellEditorManager = new Xceed.Grid.Editors.NumericEditor(EditorTemplate);

                TestDataSet.TestDataTableRow Row = TestDataSet.TestDataTable.NewTestDataTableRow();
                Row.Test = 10.00000000000000M;
                TestDataSet.TestDataTable.Rows.Add(Row);
            }

     
    As I understand, DisplayFormatSpecifier here means only format for displaying and it does not work when control comes to edit mode 🙁

    Imported from legacy forums. Posted by Nazar (had 462 views)

    Xceed Support
    Member
    Post count: 5658

    The problem comes from the decimal constructor which does not have the same behavior when you pass it a number ending with an M  than when you pass it a double.

    So this should work :

    Row.Test = new Decimal(10.00000000000000);

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 345 views)

    User (Old forums)
    Member
    Post count: 23064

    Yeah, I know it. But data stored in database in the way with zeros. And they come from database with zeros, since in my application I fill DataSet of course not by hand, but by using TableAdapter. I find solutions like looping through all the rows inside DataTable and calling decimal constructor I bit ugly, hope Xceed developers have nicer solution for this typical problem.

    Imported from legacy forums. Posted by Nazar (had 298 views)

    User (Old forums)
    Member
    Post count: 23064

    Up! Question is still actual…

    Imported from legacy forums. Posted by Nazar (had 491 views)

    Xceed Support
    Member
    Post count: 5658

    Do this instead:

     

     NumericEditor numericEditor = new NumericEditor();
          numericEditor.SettingControlValue += new CellEditorEventHandler( numericEditor_SettingControlValue );
          gridControl1.Columns[ 0 ].FormatSpecifier = “#.####################”;
          gridControl1.Columns[ 0 ].CellEditorManager = numericEditor;
          
      

        void numericEditor_SettingControlValue( object sender, CellEditorEventArgs e )
        {
          WinNumericTextBox winNumericTextBox = e.Control as WinNumericTextBox;

          winNumericTextBox.TextBoxArea.RawText = String.Format( “{0:#.####################}”, winNumericTextBox.Value );

        }

    Imported from legacy forums. Posted by Mohamed [Xceed] (had 1043 views)

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