■ GridView 클래스 : CustomSummaryCalculate 이벤트를 사용해 그룹 SUMMARY 커스텀 계산하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

using System.Globalization;

 

using DevExpress.Data;

using DevExpress.Utils;

using DevExpress.XtraEditors;

using DevExpress.XtraGrid.Views.Grid;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region Field

 

        /// <summary>

        /// 일자 카운트

        /// </summary>

        private int dateCount = 0;

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            this.gridView.InitializeView

            (

                true,                          // Multi Select

                GridMultiSelectMode.RowSelect, // Grid Multi Select Mode

                DrawFocusRectStyle.CellFocus,  // Draw Focus Rect Style

                true,                          // Show Indicator

                true,                          // Show Column Headers

                true,                          // Allow Column Moving

                true,                          // Allow Column Resizing

                true,                          // Allow Filter

                true,                          // Allow Sort

                false,                         // Allow Cell Merge

                EditorShowMode.Default,        // Editor Show Mode

                false                          // Editable

            );

 

            this.gridView.OptionsBehavior.AutoPopulateColumns = true;

 

            this.gridView.OptionsBehavior.AutoExpandAllGroups = true;

 

            this.gridView.OptionsView.ShowGroupPanel = true;

 

            this.gridView.OptionsView.ShowGroupedColumns = true;

 

            this.gridView.CustomSummaryCalculate += gridView_CustomSummaryCalculate;

 

            this.gridControl.DataSource = new nwindDataSetTableAdapters.OrdersTableAdapter().GetData();

 

            this.gridView.Columns["OrderDate"].GroupIndex = 0;

 

            this.gridView.GroupSummary.Add(SummaryItemType.Custom, "OrderDate", gridView.Columns["OrderDate"], "{0} this week");

 

            this.gridView.BestFitColumns();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 그리드 뷰 SUMMARY 커스텀 계산하기 - gridView_CustomSummaryCalculate(sender, e)

 

        /// <summary>

        /// 그리드 뷰 SUMMARY 커스텀 계산하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void gridView_CustomSummaryCalculate(object sender, CustomSummaryEventArgs e)

        {

            if(e.IsGroupSummary)

            {

                GridView gridView = sender as GridView;

 

                switch(e.SummaryProcess)

                {

                    case CustomSummaryProcess.Start :

 

                        dateCount = 0;

 

                        break;

 

                    case CustomSummaryProcess.Calculate :

 

                        DateTime orderDate = Convert.ToDateTime(gridView.GetRowCellValue(e.RowHandle, gridView.Columns["OrderDate"]));

 

                        DateTime currentDate = DateTime.Now;

 

                        CultureInfo cultureInfo = CultureInfo.CurrentCulture;

 

                        int orderDateWeek = cultureInfo.Calendar.GetWeekOfYear

                        (

                            orderDate,

                            CalendarWeekRule.FirstDay,

                            DayOfWeek.Monday

                        );

 

                        int currentDateWeek = cultureInfo.Calendar.GetWeekOfYear

                        (

                            currentDate,

                            CalendarWeekRule.FirstDay,

                            DayOfWeek.Monday

                        );

 

                        if(orderDateWeek == currentDateWeek)

                        {

                            dateCount++;

                        }

 

                        break;

 

                        case CustomSummaryProcess.Finalize :

 

                            e.TotalValue = dateCount;

 

                            break;

                }

            }

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

'DevExpress > WinForm' 카테고리의 다른 글

[DEVEXPRESS/WINFORM] GridView 클래스 : MasterRowExpanded 이벤트를 사용해 마스터 행 확장시 처리하기  (0) 15:15:18
[DEVEXPRESS/WINFORM] GridView 클래스 : 마스터-상세 관계 설정하기  (0) 15:03:15
[DEVEXPRESS/WINFORM] GridView 클래스 : UpdateTotalSummary 메소드를 사용해 총계(Total Summary) 업데이트 하기  (0) 00:45:09
[DEVEXPRESS/WINFORM] GridView 클래스 : GetGroupSummaryValues 메소드를 사용해 그룹 SUMMARY 값 구하기  (0) 00:22:18
[DEVEXPRESS/WINFORM] GridView 클래스 : GetRowSummaryItem 메소드를 사용해 SUMMARY 항목 구하기  (0) 2020.04.03
[DEVEXPRESS/WINFORM] GridView 클래스 : CustomSummaryCalculate 이벤트를 사용해 그룹 SUMMARY 커스텀 계산하기  (0) 2020.04.03
[DEVEXPRESS/WINFORM] GridColumnSummaryItem 클래스 : 총계(Total Summary) 표시하기  (0) 2020.04.03
[DEVEXPRESS/WINFORM] OptionsColumnFilter 클래스 : PopupExcelFilterGrouping 속성을 사용해 팝업 엑셀 필터 그룹 사용하기  (0) 2020.04.02
[DEVEXPRESS/WINFORM] GridView 클래스 : ShowFilterPopupDate 이벤트를 사용해 필터 팝업 엑셀 일자 표시하기  (0) 2020.04.02
[DEVEXPRESS/WINFORM] GridView 클래스 : FilterPopupExcelData 이벤트를 사용해 필터 팝업 엑셀 데이터 처리하기  (0) 2020.04.02
[DEVEXPRESS/WINFORM] GridView 클래스 : ShowFilterPopupExcel 이벤트를 사용해 필터 팝업 엑셀 표시하기  (0) 2020.04.02
Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요