Aggregate on calculated columns, how?

6 posts, 0 answers
  1. fruzicka
    fruzicka avatar
    27 posts
    Member since:
    Oct 2012

    Posted 20 Nov 2008 Link to this post

    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.
  2. Kevin
    Kevin avatar
    16 posts
    Member since:
    Nov 2007

    Posted 21 Nov 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. fruzicka
    fruzicka avatar
    27 posts
    Member since:
    Oct 2012

    Posted 22 Nov 2008 Link to this post

    /** 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.



  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 24 Nov 2008 Link to this post

    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.
  6. fruzicka
    fruzicka avatar
    27 posts
    Member since:
    Oct 2012

    Posted 24 Nov 2008 Link to this post

    I found following issue:
    I have one checkbox column in the gridview, as soon as I remove it, everything is working ...
    Strange.

  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 28 Nov 2008 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready