본문 바로가기
Winform

Devexpress Grid CustomSummaryCalculate(그리드 특정 조건만 sum)

by 캡틴노랑이 2019. 5. 21.
반응형

그리드의 summary에 특정 조건의 값만 합할 때 다음 코드를 사용.

//전역
double AAA = 0;
int BBB = 0;

//Calc
advBandedGridViewDetail.CustomSummaryCalculate += (sender, e) =>
{
    AdvBandedGridView view = sender as AdvBandedGridView;
    switch (e.SummaryProcess)
    {
        case DevExpress.Data.CustomSummaryProcess.Start:
            if (((DevExpress.XtraGrid.GridColumnSummaryItem)e.Item).FieldName == "AAA")
                AAA = 0;
            if (((DevExpress.XtraGrid.GridColumnSummaryItem)e.Item).FieldName == "BBB")
                BBB = 0;
            break;
        case DevExpress.Data.CustomSummaryProcess.Calculate:
            if (view.GetRowCellValue(e.RowHandle, view.Columns["CNCL_YN"]).ToString() == "N")
            {
                if(((DevExpress.XtraGrid.GridColumnSummaryItem)e.Item).FieldName== "AAA")
                    AAA += double.Parse(view.GetRowCellValue(e.RowHandle, "AAA").ToString());
                if (((DevExpress.XtraGrid.GridColumnSummaryItem)e.Item).FieldName == "BBB")
                    BBB += int.Parse(view.GetRowCellValue(e.RowHandle, "BBB").ToString());
            }
            break;
        case DevExpress.Data.CustomSummaryProcess.Finalize:
            if (((DevExpress.XtraGrid.GridColumnSummaryItem)e.Item).FieldName == "WRHS_QN_UNIT")
                e.TotalValue = AAA;
            if (((DevExpress.XtraGrid.GridColumnSummaryItem)e.Item).FieldName == "BBB")
                e.TotalValue = BBB;
            
            break;
    }               
};

//
advBandedGridViewDetail.Columns["AAA"].Summary.Add(DevExpress.Data.SummaryItemType.Custom, "AAA", "{0:#,##0}");
advBandedGridViewDetail.Columns["BBB"].Summary.Add(DevExpress.Data.SummaryItemType.Custom, "BBB", "{0:#,##0}");
반응형

댓글