DecimalPlaces in GridViewDecimalColumn doesn't work

4 posts, 1 answers
  1. Sandi Markon
    Sandi Markon avatar
    101 posts
    Member since:
    Jul 2012

    Posted 25 Jan 2010 Link to this post

    No matter what I set to value DecimalPlaces, grid displays number of decimal places from database.
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 27 Jan 2010 Link to this post

    Hello Sandi Markon,

    I was able to reproduce the issue. Indeed, you cannot currently set the DecimalPlaces property of GridViewDecimalColumn. However, you can use the following code snippet as a workaround:
    void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        GridSpinEditor spinEditor = this.radGridView1.ActiveEditor as GridSpinEditor;
        if (spinEditor != null)
        {
            spinEditor.DecimalPlaces = 3;
        }
    }

    Basically, you should subscribe to the RadGridView.CellEditorInitialized event and set the DecimalPlaces property of the GridSpinEditor itself.

    I am updating your Telerik points for the report. If you have additional questions, feel free to contact me.

    Regards,
    Svett
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Versile
    Versile avatar
    20 posts
    Member since:
    May 2009

    Posted 21 May 2010 Link to this post

    This obviously had no effect when your not in edit mode so as a workaround subscribe to cellformatting event

            private void radGridMain_CellFormatting(object sender, CellFormattingEventArgs e) 
            { 
                if (e.CellElement.ColumnInfo is GridViewDecimalColumn) 
                { 
                    e.CellElement.Text = String.Format("{0:N2}", ((GridDataCellElement)e.CellElement).Value); 
                } 
            } 

    Surprisingly there is no GridDecimalElement like the others have their own element, but this works.
  5. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 27 May 2010 Link to this post

    Hello Versile,

    My code snippet shows how you can set the decimal places of GridSpinEditor. It does not affect the formatting of the cell element. In addition, you need to set FormatString property of GridViewDecimalColumn. You can use this code snippet:
    this.radGridView.Columns["DecimalColumn"].FormatString = "{0:N2}";

    Greetings,
    Svett
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top