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

Customizing Gridlevel totals

5 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
RS
Top achievements
Rank 1
RS asked on 19 Aug 2012, 06:18 PM
Hi,

My grid has been grouped and ShowTotals is true.  I need not display totals for all columns.  I need to display show totals only for specific fields.  Request you to let me know if i need to set any properties or write any events to get this feature.

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
RS
Top achievements
Rank 1
answered on 21 Aug 2012, 12:30 PM
Can anybody help me out?
0
Jack
Telerik team
answered on 22 Aug 2012, 01:35 PM
Hello,

I am not sure that I correctly understand your question. You can specify the field to be summarized in GridViewSummaryItem constructor by using its first argument. Consider the following code which adds a summary item for the Value column which calculates its sum:
this.radGridView1.SummaryRowsTop.Add(new GridViewSummaryRowItem());
this.radGridView1.SummaryRowsTop[0].Add(new GridViewSummaryItem("Value", "Sum: {0}", GridAggregateFunction.Sum));

Find further details are available in our online documentation.
 
Kind regards,
Jack
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
RS
Top achievements
Rank 1
answered on 22 Aug 2012, 06:07 PM
Thanks for your response.  My requirement is bit different. 

I have a grid with Columns A, B, C, D.  It was grouped on Column A.   I have added summary items on  Column C, Column D.  Also set "Show Totals = true" to display table level summary.  Now grid is showing group level totals and table level totals for Columns C & D.  But my requirement is Table level summary should be displayed only on Column D and Group level summary should be displayed on both Column C & D.

Is it possible to customize only table level summary (Show Totals)?
0
Accepted
Jack
Telerik team
answered on 27 Aug 2012, 02:15 PM
Hi,

Yes, you can hide the summary cell text by setting the DrawText property for the GridSummaryCellElement to false. This can be done when handling the ViewCellFormatting event. Here is a sample:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridSummaryCellElement summaryCell = e.CellElement as GridSummaryCellElement;
    if (summaryCell != null)
    {
        GridViewSummaryRowInfo summaryRow = summaryCell.RowInfo as GridViewSummaryRowInfo;
        if (summaryRow.Tag == null)
        {
            GridTraverser traverser = new GridTraverser(this.radGridView1.MasterView);
            GridViewGroupRowInfo group = null;
            while (traverser.MoveNext())
            {
                if (traverser.Current is GridViewGroupRowInfo)
                {
                    group = traverser.Current as GridViewGroupRowInfo;
                }
                if (traverser.Current == summaryRow)
                {
                    if (group != null && group.BottomSummaryRows.Contains(summaryRow))
                    {
                        summaryRow.Tag = group;
                    }
                    break;
                }
            }
        }
 
        if (summaryCell.ColumnInfo.Name == "Value")
        {
            summaryCell.DrawText = summaryRow.Tag != null;
        }
    }
}

Regards,

Jack
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
RS
Top achievements
Rank 1
answered on 04 Sep 2012, 10:00 AM
Thank you verymuch. It is perfectly working.
Tags
GridView
Asked by
RS
Top achievements
Rank 1
Answers by
RS
Top achievements
Rank 1
Jack
Telerik team
Share this question
or