如何在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吗?如果是,如何使用此类型?

谁能帮我?

谢谢

最佳答案

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

对我来说很完美

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

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


在百分比列中创建了一个custom summary type,在选项Tag中键入了percentageColumnCustomSummary,这是该摘要列的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);
            }

        }


这很棒!

10-04 16:36