3

xtraGrid gridControl にカスタム summerType を追加するにはどうすればよいですか?

他の 2 つの列のパーセンテージを計算する名前付きSummerItemの列にを追加したいと思います。xtraGrid gridControltotal percent

合計で、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

私にぴったりの作品

クラスに 2 つのプライベート変数を作成します

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);
            }

        }

これはうまくいきます!

于 2014-05-08T09:05:09.737 に答える