3

如何在 xtraGrid gridControl 中添加自定义summerType?

我想SummerItem在我xtraGrid gridControl命名total percent的 whitch 的列中添加一个,将计算其他两列的百分比。

我总共有 3 列 1. 项目 A 的数量 2. 总数量和 3. 百分比

我也summaryItems

1. Sum of column 1 (`Quantities of Item A`)
2. Sum of column 2 (`Total Quantities`) and 
3. Total Percentage whitch I would like to make a divition with ( column 1 / column 2 ) * 100

我的问题是我该怎么做?我应该使用Custom Summary Type? 如果是,如何使用这种类型?

谁能帮我?

谢谢

4

1 回答 1

0

我在这里找到了解决方案 https://documentation.devexpress.com/#windowsforms/DevExpressXtraGridViewsGridGridView_CustomSummaryCalculatetopic

非常适合我

我在课堂上创建了两个私有变量

private decimal _sumOfValues = 0;
private decimal _sumOfTotalValue = 0;

在百分比列中创建了一个custom summary type并在选项Tag中键入percentageColumnCustomSummarywhitch 是此摘要列的 ID

在我的 xtraGrid 上创建一个事件

private void allocationGridView_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) 

并输入以下代码

private void allocationGridView_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) 
        {
            try
            {
                //int summaryID = Convert.ToInt32((e.Item as GridSummaryItem).Tag);
                string summaryTag = Convert.ToString((e.Item as GridSummaryItem).Tag);
                GridView View = sender as GridView;

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

                    _sumOfValues = 0;
                    _sumOfTotalValue = 0;
                }

                //Calculate
                if (e.SummaryProcess == CustomSummaryProcess.Calculate) {

                    decimal colValueColumnValue = Convert.ToDecimal( View.GetRowCellValue(e.RowHandle, "Value") );
                    decimal colTotalValueColumnValue = Convert.ToDecimal( View.GetRowCellValue(e.RowHandle, "TotalValue") );

                    switch (summaryTag) {
                        case "percentageColumnCustomSummary":
                            _sumOfValues += colValueColumnValue;
                            _sumOfTotalValue += colTotalValueColumnValue;
                            break;
                    }
                }

                // Finalization 
                if (e.SummaryProcess == CustomSummaryProcess.Finalize) {
                    switch (summaryTag) {
                        case "percentageColumnCustomSummary":
                            e.TotalValue = 0;
                            if (_sumOfTotalValue != 0) {
                                e.TotalValue = (_sumOfValues / _sumOfTotalValue);
                            }

                            break;
                    }
                }  
            }
            catch (System.Exception ex)
            {
                _logger.ErrorException("allocationGridView_CustomSummaryCalculate", ex);
            }

        }

这很好用!

于 2014-05-08T09:05:09.737 回答