첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    Width="800"
    Height="600"
    Title="GridControl 클래스 : CustomSummary 이벤트를 사용해 값이 비어있는 셀 계수하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <dxg:GridControl x:Name="gridControl"
            CustomSummary="gridControl_CustomSummary"
            GroupCount="1">
            <dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="Text"   />
                <dxg:GridColumn FieldName="Number" />
            </dxg:GridControl.Columns>
            <dxg:GridControl.SortInfo>
                <dxg:GridSortInfo FieldName="Text" />
            </dxg:GridControl.SortInfo>
            <dxg:GridControl.GroupSummary>
                <dxg:GridSummaryItem
                    FieldName="Number"
                    SummaryType="Custom" 
                    DisplayFormat="Group empty cells count : {0}" />
            </dxg:GridControl.GroupSummary>
            <dxg:GridControl.TotalSummary>
                <dxg:GridSummaryItem
                    FieldName="Number"
                    SummaryType="Custom" 
                    DisplayFormat="Total empty cells count : {0}"/>
            </dxg:GridControl.TotalSummary>
            <dxg:GridControl.View>
                <dxg:TableView x:Name="tableView"
                    ShowTotalSummary="True"
                    NavigationStyle="Cell" />
            </dxg:GridControl.View>
        </dxg:GridControl>
    </Grid>
</Window>

 

728x90

 

▶ MainWindow.xaml.cs

using System.Windows;
using System.Collections.Generic;

using DevExpress.Data;
using DevExpress.Xpf.Grid;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 샘플 데이터 리스트
        /// </summary>
        private List<SampleData> sampleDataList;

        /// <summary>
        /// 빈 셀 전체 수
        /// </summary>
        private int emptyCellTotalCount = 0;

        /// <summary>
        /// 빈 셀 그룹 수
        /// </summary>
        private int emptyCellGroupCount = 0;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            this.sampleDataList = new List<SampleData>();

            for(int i = 0; i < 100; i++)
            {
                this.sampleDataList.Add(new SampleData() { Text = "group " + i % 10, Number = i });

                if(i % 3 == 0)
                {
                    this.sampleDataList[i].Number = null;
                }
            }

            this.gridControl.ItemsSource = this.sampleDataList;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 그리드 컨트롤 커스텀 요약 처리하기 - gridControl_CustomSummary(sender, e)

        /// <summary>
        /// 그리드 컨트롤 커스텀 요약 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void gridControl_CustomSummary(object sender, CustomSummaryEventArgs e)
        {
            if((e.Item as GridSummaryItem).FieldName != "Number")
            {
                return;
            }

            if(e.IsTotalSummary)
            {
                if(e.SummaryProcess == CustomSummaryProcess.Start)
                {
                    this.emptyCellTotalCount = 0;
                }

                if(e.SummaryProcess == CustomSummaryProcess.Calculate)
                {
                    int? fieldValue = (int?)e.FieldValue;

                    if(!fieldValue.HasValue)
                    {
                        this.emptyCellTotalCount++;
                    }

                    e.TotalValue = this.emptyCellTotalCount;
                }
            }

            if(e.IsGroupSummary)
            {
                if(e.SummaryProcess == CustomSummaryProcess.Start)
                {
                    this.emptyCellGroupCount = 0;
                }

                if(e.SummaryProcess == CustomSummaryProcess.Calculate)
                {
                    int? fieldValue = (int?)e.FieldValue;

                    if(!fieldValue.HasValue)
                    {
                        this.emptyCellGroupCount++;
                    }

                    e.TotalValue = this.emptyCellGroupCount;
                }
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker

댓글을 달아 주세요