첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

using System.Drawing;
using System.Windows.Forms;

using DevExpress.Data;
using DevExpress.Utils;
using DevExpress.XtraPivotGrid;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

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

            #region 피벗 그리드 컨트롤을 설정한다.

            this.pivotGridControl.Margin = new Padding(0);

            Font defaultFont = new Font("나눔고딕코딩", 12f);

            this.pivotGridControl.Appearance.Cell.Font                     = defaultFont;
            this.pivotGridControl.Appearance.ColumnHeaderArea.Font         = defaultFont;
            this.pivotGridControl.Appearance.CustomTotalCell.Font          = defaultFont;
            this.pivotGridControl.Appearance.DataHeaderArea.Font           = defaultFont;
            this.pivotGridControl.Appearance.Empty.Font                    = defaultFont;
            this.pivotGridControl.Appearance.ExpandButton.Font             = defaultFont;
            this.pivotGridControl.Appearance.FieldHeader.Font              = defaultFont;
            this.pivotGridControl.Appearance.FieldValue.Font               = defaultFont;
            this.pivotGridControl.Appearance.FieldValueGrandTotal.Font     = defaultFont;
            this.pivotGridControl.Appearance.FieldValueTotal.Font          = defaultFont;
            this.pivotGridControl.Appearance.FilterHeaderArea.Font         = defaultFont;
            this.pivotGridControl.Appearance.FilterSeparator.Font          = defaultFont;
            this.pivotGridControl.Appearance.FocusedCell.Font              = defaultFont;
            this.pivotGridControl.Appearance.GrandTotalCell.Font           = defaultFont;
            this.pivotGridControl.Appearance.HeaderArea.Font               = defaultFont;
            this.pivotGridControl.Appearance.HeaderFilterButton.Font       = defaultFont;
            this.pivotGridControl.Appearance.HeaderFilterButtonActive.Font = defaultFont;
            this.pivotGridControl.Appearance.HeaderGroupLine.Font          = defaultFont;
            this.pivotGridControl.Appearance.Lines.Font                    = defaultFont;
            this.pivotGridControl.Appearance.PrefilterPanel.Font           = defaultFont;
            this.pivotGridControl.Appearance.RowHeaderArea.Font            = defaultFont;
            this.pivotGridControl.Appearance.SelectedCell.Font             = defaultFont;
            this.pivotGridControl.Appearance.TotalCell.Font                = defaultFont;

            this.pivotGridControl.Appearance.Cell.Options.UseFont                     = true;
            this.pivotGridControl.Appearance.ColumnHeaderArea.Options.UseFont         = true;
            this.pivotGridControl.Appearance.CustomTotalCell.Options.UseFont          = true;
            this.pivotGridControl.Appearance.DataHeaderArea.Options.UseFont           = true;
            this.pivotGridControl.Appearance.Empty.Options.UseFont                    = true;
            this.pivotGridControl.Appearance.ExpandButton.Options.UseFont             = true;
            this.pivotGridControl.Appearance.FieldHeader.Options.UseFont              = true;
            this.pivotGridControl.Appearance.FieldValue.Options.UseFont               = true;
            this.pivotGridControl.Appearance.FieldValueGrandTotal.Options.UseFont     = true;
            this.pivotGridControl.Appearance.FieldValueTotal.Options.UseFont          = true;
            this.pivotGridControl.Appearance.FilterHeaderArea.Options.UseFont         = true;
            this.pivotGridControl.Appearance.FilterSeparator.Options.UseFont          = true;
            this.pivotGridControl.Appearance.FocusedCell.Options.UseFont              = true;
            this.pivotGridControl.Appearance.GrandTotalCell.Options.UseFont           = true;
            this.pivotGridControl.Appearance.HeaderArea.Options.UseFont               = true;
            this.pivotGridControl.Appearance.HeaderFilterButton.Options.UseFont       = true;
            this.pivotGridControl.Appearance.HeaderFilterButtonActive.Options.UseFont = true;
            this.pivotGridControl.Appearance.HeaderGroupLine.Options.UseFont          = true;
            this.pivotGridControl.Appearance.Lines.Options.UseFont                    = true;
            this.pivotGridControl.Appearance.PrefilterPanel.Options.UseFont           = true;
            this.pivotGridControl.Appearance.RowHeaderArea.Options.UseFont            = true;
            this.pivotGridControl.Appearance.SelectedCell.Options.UseFont             = true;
            this.pivotGridControl.Appearance.TotalCell.Options.UseFont                = true;

            this.pivotGridControl.Appearance.FieldValue.TextOptions.HAlignment = HorzAlignment.Center;

            PivotGridField category1Field = new PivotGridField();

            category1Field.Name                                     = string.Empty;
            category1Field.Caption                                  = "대분류";
            category1Field.FieldName                                = "CATEGORY1";
            category1Field.Area                                     = PivotArea.ColumnArea;
            category1Field.AreaIndex                                = 0;
            category1Field.Appearance.Header.Options.UseTextOptions = true;
            category1Field.Appearance.Header.TextOptions.HAlignment = HorzAlignment.Center;
            category1Field.Appearance.Cell.Options.UseTextOptions   = true;
            category1Field.Appearance.Cell.TextOptions.HAlignment   = HorzAlignment.Default;
            category1Field.CellFormat.FormatType                    = FormatType.None;
            category1Field.CellFormat.FormatString                  = null;
            category1Field.UnboundType                              = UnboundColumnType.Bound;

            PivotGridField category2Field = new PivotGridField();

            category2Field.Name                                     = string.Empty;
            category2Field.Caption                                  = "중분류";
            category2Field.FieldName                                = "CATEGORY2";
            category2Field.Area                                     = PivotArea.ColumnArea;
            category2Field.AreaIndex                                = 1;
            category2Field.Appearance.Header.Options.UseTextOptions = true;
            category2Field.Appearance.Header.TextOptions.HAlignment = HorzAlignment.Center;
            category2Field.Appearance.Cell.Options.UseTextOptions   = true;
            category2Field.Appearance.Cell.TextOptions.HAlignment   = HorzAlignment.Default;
            category2Field.CellFormat.FormatType                    = FormatType.None;
            category2Field.CellFormat.FormatString                  = null;
            category2Field.UnboundType                              = UnboundColumnType.Bound;

            PivotGridField yyyyMMField = new PivotGridField();

            yyyyMMField.Name                                     = string.Empty;
            yyyyMMField.Caption                                  = "연월";
            yyyyMMField.FieldName                                = "YYYYMM";
            yyyyMMField.Area                                     = PivotArea.RowArea;
            yyyyMMField.AreaIndex                                = 0;
            yyyyMMField.Appearance.Header.Options.UseTextOptions = true;
            yyyyMMField.Appearance.Header.TextOptions.HAlignment = HorzAlignment.Center;
            yyyyMMField.Appearance.Cell.Options.UseTextOptions   = true;
            yyyyMMField.Appearance.Cell.TextOptions.HAlignment   = HorzAlignment.Center;
            yyyyMMField.CellFormat.FormatType                    = FormatType.None;
            yyyyMMField.CellFormat.FormatString                  = null;
            yyyyMMField.UnboundType                              = UnboundColumnType.Bound;

            PivotGridField amountField = new PivotGridField();

            amountField.Name                                     = string.Empty;
            amountField.Caption                                  = "금액";
            amountField.FieldName                                = "AMOUNT";
            amountField.Area                                     = PivotArea.DataArea;
            amountField.AreaIndex                                = 0;
            amountField.Appearance.Header.Options.UseTextOptions = true;
            amountField.Appearance.Header.TextOptions.HAlignment = HorzAlignment.Center;
            amountField.Appearance.Cell.Options.UseTextOptions   = true;
            amountField.Appearance.Cell.TextOptions.HAlignment   = HorzAlignment.Far;
            amountField.CellFormat.FormatType                    = FormatType.Numeric;
            amountField.CellFormat.FormatString                  = "#,##0";
            amountField.UnboundType                              = UnboundColumnType.Bound;

            this.pivotGridControl.Fields.Add(category1Field);
            this.pivotGridControl.Fields.Add(category2Field);
            this.pivotGridControl.Fields.Add(yyyyMMField   );
            this.pivotGridControl.Fields.Add(amountField   );

            #endregion
            #region 이벤트를 설정한다.

            this.pivotGridControl.FieldValueDisplayText += pivotGridControl_FieldValueDisplayText;

            #endregion

            this.pivotGridControl.DataSource = Item.GetItemList();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 피벗 그리드 컨트롤 필드 값 표시 텍스트 처리하기 - pivotGridControl_FieldValueDisplayText(sender, e)

        /// <summary>
        /// 피벗 그리드 컨트롤 필드 값 표시 텍스트 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void pivotGridControl_FieldValueDisplayText(object sender, PivotFieldDisplayTextEventArgs e)
        {
            if(e.ValueType == PivotGridValueType.GrandTotal)
            {
                if(e.IsColumn)
                {
                    e.DisplayText = "소계";
                }
                else
                {
                    e.DisplayText = "총계";
                }
            }
            else if(e.ValueType == PivotGridValueType.Total)
            {
                e.DisplayText = $"{e.Value} 소계";
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요