,我發現這裏的解決方案 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);
}
}
這個偉大的工程!