我在这里找到了解决方案
https://documentation.devexpress.com/#windowsforms/DevExpressXtraGridViewsGridGridView_CustomSummaryCalculatetopic
非常适合我
我在课堂上创建了两个私有变量
private decimal _sumOfValues = 0;
private decimal _sumOfTotalValue = 0;
在百分比列中创建了一个custom summary type
并在选项Tag
中键入percentageColumnCustomSummary
whitch 是此摘要列的 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);
}
}
这很好用!