2014-05-06 49 views
3

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

我想將SummerItem添加到我的xtraGrid gridControl中名爲total percent的列中,以計算其他兩列的百分比。

我總共有3列項 1.量一 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?如果是的話,如何使用這種類型?

任何人都可以幫助我嗎?

感謝

回答

0

,我發現這裏的解決方案 https://documentation.devexpress.com/#windowsforms/DevExpressXtraGridViewsGridGridView_CustomSummaryCalculatetopic

工作非常適合我

我創造我的課

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

兩個私有變量的百分比列創建一個custom summary type並在選項Tag中鍵入percentageColumnCustomSummary whitc h是本摘要列

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

     } 

這個偉大的工程!

相關問題