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

Aggregate on calculated columns, how?

5 Answers 275 Views
GridView
This is a migrated thread and some comments may be shown as answers.
fruzicka
Top achievements
Rank 1
fruzicka asked on 20 Nov 2008, 10:37 PM
Is the subject possible? I have one per expression calculated column on which I would like to count summary.
I can't get it working ...

Thanks in advance for any help.

F.

5 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 22 Nov 2008, 02:55 AM
This may have to be modified a bit for the Q3 2008, but this worked in Q2 2008

grid_Territory.Columns("Prospects").Expression = "NumEmployees-NumActiveClients-NumInactiveClients"

Dim totalRow As GridViewSummaryRowItem = New GridViewSummaryRowItem
totalRow.Add(New GridViewSummaryItem("Prospects", "{0}", GridAggregateFunction.Sum))
grid_Territory.MasterGridViewTemplate.SummaryRowsBottom.Add(totalRow)

My guess is you would replace .Sum with .Count.

Good Luck!

--Kdc
0
fruzicka
Top achievements
Rank 1
answered on 22 Nov 2008, 12:44 PM
/** CALCULATED COLUMN **/ 
GridViewTextBoxColumn cTotalPrice = new GridViewTextBoxColumn(); 
cTotalPrice.DataType = typeof(System.Nullable<decimal>); 
cTotalPrice.IsAutoGenerated = false
cTotalPrice.UniqueName = "TotalPrice"
cTotalPrice.FieldName = "TotalPrice"
cTotalPrice.FormatString = "{0:#,###,###,##0.00}"
rgv.MasterGridViewTemplate.Columns.Add(TotalPrice); 
rgv.Columns["TotalPrice"].Expression = 
    "ISNULL(" + Metadata.ColumnNames.Units + ", 0) * ISNULL(" + Metadata.ColumnNames.Price + ", 0)"
 
GridViewSummaryRowItem rTotals = new GridViewSummaryRowItem(); 
rTotals.Add(new GridViewSummaryItem("TotalPrice""{0:#,###,###,##0.00}", GridAggregateFunction.Sum)); 
rgv.MasterGridViewTemplate.SummaryRowsBottom.Add(rTotals); 

the calculated column is working fine, but no summary is show. There is a exception in output window:

A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
   at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
   at System.Data.RBTree`1.get_Item(Int32 index)
   at System.Data.DataRowCollection.get_Item(Int32 index)
   at Telerik.WinControls.Data.DataAccessComponent.EnsureIndexColumn(String columnName)
   at Telerik.WinControls.Data.DataAccessComponent.CalculateColumnExpression(GridViewDataColumn column)
   at Telerik.WinControls.Data.DataAccessComponent.EnsureColumns()
   at Telerik.WinControls.UI.GridViewDataColumn.set_Expression(String value)

Anyway, thanks for help.



0
Martin Vasilev
Telerik team
answered on 24 Nov 2008, 08:38 AM
Hi fruzicka,

Thank you for the question.

There are no restrictions for adding aggregates to an expression column. Please, review the code-block below that demonstrates this:
 
private void AddExpressionColumn() 
    GridViewDataColumn col = new GridViewDataColumn(); 
    col.HeaderText = "Value"
    col.UniqueName = "Value"
    col.Width = 150; 
    this.radGridView1.Columns.Add(col); 
    this.radGridView1.Columns["Value"].Expression = "UnitPrice * Quantity"
 
    GridViewSummaryRowItem total = new GridViewSummaryRowItem(); 
    total.Add(new GridViewSummaryItem("Value""Sum: {0}", GridAggregateFunction.Sum)); 
 
    this.radGridView1.MasterGridViewTemplate.SummaryRowsTop.Add(total); 

Hope this helps. If you have any other questions, do not hesitate to contact me again.

All the best,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
fruzicka
Top achievements
Rank 1
answered on 24 Nov 2008, 05:03 PM
I found following issue:
I have one checkbox column in the gridview, as soon as I remove it, everything is working ...
Strange.

0
Martin Vasilev
Telerik team
answered on 28 Nov 2008, 08:23 AM
Hello fruzicka,

Thank you for getting back to me.

I did not managed to reproduce the described issue locally. Find attached an example project with summaries on calculated columns when RadGridView contains a CheckBox column. May be the issue is related to something specific in your scenario.

If you still experience the issue please, send me a small example application that demonstrates it (you can do so in a support ticket). This will help me to investigate your case and provide you with further assistance.

Contact me again if you need additional assistance.

Best wishes,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
fruzicka
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
fruzicka
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or