in
Forums
Blogs
DevExpress.com
Client Center
Support Center
DevExpress Channel

The One With

Silverlight DataGrid - How to perform custom summary calculations within the grid control

There are 5 build-in aggregate functions that our Silverlight DataGrid supports (Max, Min, Avg, Sum and Count), and an ability to define custom ones.

 

 

Using build-in Summary Items

<DevExpress:AgDataGrid>

   <DevExpress:AgDataGrid.Totals>

       <DevExpress:AgDataGridSummaryItem FieldName="Points" SummaryType="Average"/>

       <DevExpress:AgDataGridSummaryItem FieldName="Points" SummaryType="Max"/>

       <DevExpress:AgDataGridSummaryItem FieldName="Points" SummaryType="Min"/>

       <DevExpress:AgDataGridSummaryItem FieldName="Points" SummaryType="Count"/>

       <DevExpress:AgDataGridSummaryItem FieldName="Points" SummaryType="Sum"/>  

   </DevExpress:AgDataGrid.Totals>

</DevExpress>

 

Calculating Custom Summary

To calculate custom summary, we need to add an AgDataGridSummaryItem with SummaryType of "Custom" and use the AgDataGrid.CustomSummary event.

<DevExpress:AgDataGrid CustomSummary="myGrid_CustomSummary">

   <DevExpress:AgDataGrid.Totals>

         <DevExpress:AgDataGridSummaryItem FieldName="Points" SummaryType="Custom"

                                          Title="Sum Of Even Rows"/>

   </DevExpress:AgDataGrid.Totals>

</DevExpress>

private void myGrid_CustomSummary(object sender, DevExpress.Windows.Data.CustomSummaryEventArgs e) {              

                  if (e.SummaryProcess == CustomSummaryProcess.Start) {

                        int rowHandle = 0;                       

                        int sumOfEvenRows = 0;

                        int i = 1;

                        while (myGrid.IsValidRowHandle(rowHandle)) {

                              Item item = (Item)myGrid.GetDataRow(rowHandle);

                              if ((i % 2) == 0){

                            sumOfEvenRows += item.Points;

                              }

                              rowHandle++;

                              i++;

                        }

                        e.TotalValue = sumOfEvenRows;

                        e.TotalValueReady = true;

               }

}

public class MyRowItem {

      public int Points { get; set; }

}

All we are doing here is going through every row in our data source and summing up the Points for even rows.

 

Previous: Silverlight DataGrid - Where are my Facebook friends?

 

Cheers,

Azret

Published Jul 11 2008, 11:31 AM by Azret Botash (Developer Express)
Filed under: ,
Technorati tags: Silverlight, AgDataGrid

Comments

 

The One With said:

So I was writing a blog on how to bind data to our Silverlight DataGrid from a WebService call and got

July 11, 2008 4:49 PM
 

Community Blogs said:

Azret Botash with a series on the Devexpress Grid, Martin Mihaylov on JSON Serialization, Lee on UserControl

July 12, 2008 2:57 AM
 

Silverlight news for July 14, 2008 said:

Pingback from  Silverlight news for July 14, 2008

July 14, 2008 5:33 AM
 

cnblogs.com said:

ASPX: 1.在WEB项目中同时使用 C# AND VB 开发: 2. 微软SQL注入分析工具源代码下载。 3. 某些网站可能无法在 Internet Explorer 8 Beta 1 中正确显示的解决方案

July 17, 2008 10:29 AM
 

真见 said:

ASPX:

July 17, 2008 10:35 AM

Leave a Comment

(required)  
(optional)
(required)  
Verification code: Required
   
Add
Copyright © 1998-2010 Developer Express Inc.
ALL RIGHTS RESERVED