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

Calculated Columns (Column Expressions)

2 Answers 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chakkrit
Top achievements
Rank 1
Chakkrit asked on 09 Feb 2011, 11:15 AM
Dim col = New GridViewDecimalColumn()
col.Name = "Calculated Column"
col.HeaderText = "Order value"
RadGridView1.Columns.Add(col)
RadGridView1.Columns("Calculated Column").Expression = "UnitsOnOrder * UnitPrice"
'=========================================================
I want to use Function math.round("UnitsOnOrder * UnitPrice",3) in Column("Calculated Column").Expression
How can i calculate ?

Thank you.

2 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 09 Feb 2011, 01:47 PM
Hello,

As far as I'm aware, you cannot use a Round function in this way. The RadGridView takes it's implementation of the expression from the standard Microsoft version (see this link) which does not contain a Round function.

The CellFormatting event and ViewCellFormatting event fires for these cells, but assigning a new value to these cells does not affect the outcome. Similarly, the CellValueChanged event contains arguments that have the cell value, but these are read only.

Regards,
Richard
0
Daniel
Top achievements
Rank 1
answered on 28 Mar 2011, 12:50 PM

This is rather ugly way how to do the rounding.

RadGridView1.Columns["CalculatedColumn"].Expression =  "CONVERT(Column1 - Column2, 'System.Int32') + ',' + (CONVERT(100 * (Column1 - Column2), 'System.Int32') - (100 * CONVERT(Column1 - Column2, 'System.Int32')))";

Colon is used as decimal separator and it's rounded to 2 digits. It's actually not rounding, rather trimming, but better then nothing. And it works.

Daniel
Tags
GridView
Asked by
Chakkrit
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Share this question
or