下面的示例计算“Budget”列的取值超出 500,000 的记录的数目。 setCustomSummary 方法设置 Budget 列的自定义汇总类型。 TreeList.GetCustomSummaryValue 事件处理程序实现计算逻辑。
下面的插图展示了运行结果。
C# | 复制代码 |
---|---|
private void setCustomSummary() { treeList1.OptionsView.ShowRowFooterSummary = true; treeList1.Columns["Budget"].RowFooterSummary = SummaryItemType.Custom; treeList1.Columns["Budget"].RowFooterSummaryStrFormat = "{0} nodes exceed limit"; } private void treeList1_GetCustomSummaryValue(object sender, DevExpress.XtraTreeList.GetCustomSummaryValueEventArgs e) { if(e.Column.FieldName == "Budget") { IEnumerator en = e.Nodes.GetEnumerator(); int exceedingLimitNodes = 0; while(en.MoveNext()) { TreeListNode node = (TreeListNode)en.Current; decimal budget = (decimal)node.GetValue(e.Column); if(budget > 500000) { exceedingLimitNodes ++; //... } } e.CustomValue = exceedingLimitNodes; } } |
Visual Basic | 复制代码 |
---|---|
Private Sub setCustomSummary() TreeList1.OptionsView.ShowRowFooterSummary = True TreeList1.Columns("Budget").RowFooterSummary = SummaryItemType.Custom TreeList1.Columns("Budget").RowFooterSummaryStrFormat = "{0} nodes exceed limit" End Sub Private Sub TreeList1_GetCustomSummaryValue(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.GetCustomSummaryValueEventArgs) _ Handles TreeList1.GetCustomSummaryValue If (e.Column.FieldName = "Budget") Then Dim en As IEnumerator = e.Nodes.GetEnumerator() Dim exceedingLimitNodes As Integer = 0 Dim node As TreeListNode While en.MoveNext() = True node = CType(en.Current, TreeListNode) Dim budget As Decimal = CType(node.GetValue(e.Column), Decimal) If (budget > 500000) Then exceedingLimitNodes += 1 '... End If End While e.CustomValue = exceedingLimitNodes End If End Sub |