下面的示例展示了如何按照汇总值,对位于第一个分组层级中的分组行排序。 根据 Freight 列的取值计算分组汇总。
下面的插图展示了运行结果。
C# | 复制代码 |
---|---|
using DevExpress.Data; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Columns; GridSummaryItem summaryItemMaxFreight; private void Form1_Load(object sender, System.EventArgs e) { // ... // Creating a new summary item and adding it the view's summary item collection. summaryItemMaxFreight = gridView1.GroupSummary.Add(SummaryItemType.Max, "Freight", null, String.Empty); } private void button1_Click(object sender, System.EventArgs e) { GridColumn summaryColumn = gridView1.Columns["Freight"]; if(summaryColumn.GroupIndex < 0 && gridView1.GroupCount > 0) { GridColumn firstGroupingColumn = gridView1.SortInfo[0].Column; gridView1.GroupSummarySortInfo.Add(summaryItemMaxFreight, ColumnSortOrder.Ascending, firstGroupingColumn); } } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.Data Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Columns Dim summaryItemMaxFreight As GridSummaryItem Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load ' ... ' Creating a new summary item and adding it the view's summary item collection. summaryItemMaxFreight = GridView1.GroupSummary.Add(SummaryItemType.Max, _ "Freight", Nothing, String.Empty) End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Button1.Click Dim summaryColumn As GridColumn = GridView1.Columns("Freight") If summaryColumn.GroupIndex < 0 And GridView1.GroupCount > 0 Then Dim firstGroupingColumn As GridColumn = GridView1.SortInfo(0).Column GridView1.GroupSummarySortInfo.Add(summaryItemMaxFreight, _ ColumnSortOrder.Ascending, firstGroupingColumn) End If End Sub |