本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
================

注会练习软件
http://www.cpasoft.com.cn
我的注会软件官网

http://blog.163.com/abc7105@126/

 

 


哈哈,热爱快“过气”的DELPHI


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:注册会计师(注会)练习软件
日志总数:398
评论数量:116
留言数量:27
访问次数:3266702
建立时间:2005年6月6日




[devexpress相关控件]Display Particular Summaries for Particular Group Rows
软件技术

吕向阳 发表于 2006/9/14 20:54:40

 Display Particular Summaries for Particular Group Rows  500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> 500)this.width=500'> XtraGrid Display Particular Summaries for Particular Group Rows See Also 500)this.width=500'> Collapse All Expand All  Language Filter: All Language Filter: Multiple Language Filter: Visual Basic Language Filter: C# Language Filter: JScript By default, all group summaries are calculated for each group row. This topic shows how to hide specific group summaries for particular group rows. 500)this.width=500'> General Information Group summaries can be created at runtime via the GridView.GroupSummary collection or at design time via the grid's Group Summary Items Page. All the summaries that are specified will be calculated for each data group and displayed within each group row. Consider the following grid control that contains two group columns and so two group levels. 500)this.width=500'> Here, two group summaries are used to calculate the SUM and COUNT functions against the groups of data. You can see these functions calculated for the groups that correspond to both the 'Sales Person' and 'Category Name' group columns. 500)this.width=500'>Note Note that the GridView.GroupFormat property that specifies the group row's format is set to "{0}: [#image]{1} -- {2}" in this grid. So the summary values are separated from the group values with a double dash. In some cases it's necessary to calculate specific summaries for particular group rows, and prevent them from being calculated for rows at other group levels. For instance, in the following image the COUNT function is only calculated for the group rows that correspond to the 'Sales Person' column and is not calculated for the group rows that correspond to the 'Category Name' column: 500)this.width=500'> To only calculate group summaries for particular group rows in the XtraGrid, use the following solution: Create group summary items that represent all the group summaries that need to be calculated. Assign unique values to the GridSummaryItem.Tag properties of the summary items. These will allow you to recognize the summary items later on. Handle the GridView.CustomSummaryExists event to prevent specific summary items from being calculated for particular group rows. The GridView.CustomSummaryExists event fires for each group summary item and for each group level before a summary calculation starts. The currently processed group item and group level are identified by the event's Item and GroupLevel parameters respectively. The GroupLevel property represents an integer value that specifies the level of the current group row in the hierarchy of group rows. This can also be used to obtain the grouping column that corresponds to the current group row. To get the column, read the value in the ColumnView.GroupedColumns collection at the index matching the group level. To prevent the current summary from being calculated at the current level, set the event's Exists parameter to false. 500)this.width=500'> Example Assume that a grid control contains the 'Sales Person', 'Category Name' and 'Extended Price' columns. Data is grouped by the first two columns and summaries need to be calculated against the groups of data: 1) the COUNT function will calculate the number of records in each group, 2) the SUM function will calculate the sum of values in the 'Extended Price' column for each group. The example shows how to calculate the COUNT function against the groups that correspond to the 'Sales Person' group column and prevent it from being calculated for other groups. The SUM function will be calculated for all the data groups. Creating the group summaries Firstly let's create two group summaries (COUNT AND SUM) that need to be calculated. At design time, open the Group Summary Items Page and add two summary items by clicking the Add button. 500)this.width=500'> The first summary item will represent the COUNT function. Set its properties as follows: - FieldName to "CategoryName"; - SummaryType to Count; - Tag to 1 (a numeric value); - DisplayFormat to "Count = {0}". For the second item that will represent the SUM function set its properties as follows: - FieldName to "Extended Price"; - SummaryType to Sum; - Tag to 2 (a numeric value); - DisplayFormat to "Sum = {0:c2}" To create these group items at runtime use the following code: C# 500)this.width=500'>Copy Code GridSummaryItem item1 = gridView1.GroupSummary.Add(); item1.FieldName = "CategoryName"; item1.SummaryType = DevExpress.Data.SummaryItemType.Count; item1.Tag = 1; item1.DisplayFormat = "Count = {0}"; GridSummaryItem item2 = gridView1.GroupSummary.Add(); item2.FieldName = "Extended Price"; item2.SummaryType = DevExpress.Data.SummaryItemType.Sum; item2.Tag = 2; item2.DisplayFormat = "Sum = {0:c2}"; Visual Basic 500)this.width=500'>Copy Code Dim item1 As GridSummaryItem = gridView1.GroupSummary.Add() item1.FieldName = "CategoryName" item1.SummaryType = DevExpress.Data.SummaryItemType.Count item1.Tag = 1 item1.DisplayFormat = "Count = {0}" Dim item2 As GridSummaryItem = gridView1.GroupSummary.Add() item2.FieldName = "Extended Price" item2.SummaryType = DevExpress.Data.SummaryItemType.Sum item2.Tag = 2 item2.DisplayFormat = "Sum = {0:c2}" Implementing logic to stop particular summary calculation Handle the GridView.CustomSummaryExists event to prevent the COUNT function from being calculated for the group rows that correspond to the 'CategoryName' column: C# 500)this.width=500'>Copy Code private void gridView1_CustomSummaryExists(object sender, DevExpress.Data.CustomSummaryExistEventArgs e) { GridView view = sender as GridView; int summaryID = Convert.ToInt32((e.Item as GridSummaryItem).Tag); GridColumn groupColumn = view.GroupedColumns[e.GroupLevel]; // Do not calculate the Count summary against the group rows that correspond to the CategoryName field if(groupColumn.FieldName == "CategoryName" && summaryID == 1) { e.Exists = false; } } Visual Basic 500)this.width=500'>Copy Code Private Sub GridView1_CustomSummaryExists(ByVal sender As Object, ByVal e As DevExpress.Data.CustomSummaryExistEventArgs) _ Handles GridView1.CustomSummaryExists Dim view As GridView = CType(sender, GridView) Dim summaryID As Integer = Convert.ToInt32(CType(e.Item, GridSummaryItem).Tag) Dim groupColumn As GridColumn = view.GroupedColumns(e.GroupLevel) ' Do not calculate the Count summary against the group rows that correspond to the CategoryName field If groupColumn.FieldName = "CategoryName" And summaryID = 1 Then e.Exists = False End If End Sub The final result will be like the image below: 500)this.width=500'> The complete code of the example is shown below: C# 500)this.width=500'>Copy Code using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Columns; GridSummaryItem item1 = gridView1.GroupSummary.Add(); item1.FieldName = "CategoryName"; item1.SummaryType = DevExpress.Data.SummaryItemType.Count; item1.Tag = 1; item1.DisplayFormat = "Count = {0}"; GridSummaryItem item2 = gridView1.GroupSummary.Add(); item2.FieldName = "Extended Price"; item2.SummaryType = DevExpress.Data.SummaryItemType.Sum; item2.Tag = 2; item2.DisplayFormat = "Sum = {0:c2}"; //... private void gridView1_CustomSummaryExists(object sender, DevExpress.Data.CustomSummaryExistEventArgs e) { GridView view = sender as GridView; int summaryID = Convert.ToInt32((e.Item as GridSummaryItem).Tag); GridColumn groupColumn = view.GroupedColumns[e.GroupLevel]; // Do not calculate the Count summary against the group rows that correspond to the CategoryName field if(groupColumn.FieldName == "CategoryName" && summaryID == 1) { e.Exists = false; } } Visual Basic 500)this.width=500'>Copy Code Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Grid Imports DevExpress.XtraGrid.Columns Dim item1 As GridSummaryItem = gridView1.GroupSummary.Add() item1.FieldName = "CategoryName" item1.SummaryType = DevExpress.Data.SummaryItemType.Count item1.Tag = 1 item1.DisplayFormat = "Count = {0}" Dim item2 As GridSummaryItem = gridView1.GroupSummary.Add() item2.FieldName = "Extended Price" item2.SummaryType = DevExpress.Data.SummaryItemType.Sum item2.Tag = 2 item2.DisplayFormat = "Sum = {0:c2}" ' ... Private Sub GridView1_CustomSummaryExists(ByVal sender As Object, ByVal e As DevExpress.Data.CustomSummaryExistEventArgs) _ Handles GridView1.CustomSummaryExists Dim view As GridView = CType(sender, GridView) Dim summaryID As Integer = Convert.ToInt32(CType(e.Item, GridSummaryItem).Tag) Dim groupColumn As GridColumn = view.GroupedColumns(e.GroupLevel) ' Do not calculate the Count summary against the group rows that correspond to the CategoryName field If groupColumn.FieldName = "CategoryName" And summaryID = 1 Then e.Exists = False End If End Sub


阅读全文(4865) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.046 second(s), page refreshed 144759266 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号