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

DecimalPlaces in GridViewDecimalColumn doesn't work

3 Answers 252 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sandi Markon
Top achievements
Rank 1
Sandi Markon asked on 25 Jan 2010, 09:32 AM
No matter what I set to value DecimalPlaces, grid displays number of decimal places from database.

3 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 27 Jan 2010, 01:58 PM
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.
0
Versile
Top achievements
Rank 1
answered on 21 May 2010, 05:21 PM
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.
0
Accepted
Svett
Telerik team
answered on 27 May 2010, 07:09 AM
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.
Tags
GridView
Asked by
Sandi Markon
Top achievements
Rank 1
Answers by
Svett
Telerik team
Versile
Top achievements
Rank 1
Share this question
or