첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
0.01MB

▶ Revenue.cs

using System;
using System.Collections.Generic;

namespace TestProject
{
    /// <summary>
    /// 수입
    /// </summary>
    public class Revenue
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 국가 배열
        /// </summary>
        private static string[] _countrArray = new string[] { "한국", "미국", "중국", "러시아", "인도" };

        /// <summary>
        /// 분야 배열
        /// </summary>
        private static string[] _categoryArray = new string[] { "영화", "게임", "출판", "패션" };

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 국가 - Country

        /// <summary>
        /// 국가
        /// </summary>
        public string Country { get; set; }

        #endregion
        #region 분야 - Category

        /// <summary>
        /// 분야
        /// </summary>
        public string Category { get; set; }

        #endregion
        #region 금액 - Amount

        /// <summary>
        /// 금액
        /// </summary>
        public decimal Amount { get; set; }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 리스트 구하기 - GetList(count)

        /// <summary>
        /// 리스트 구하기
        /// </summary>
        /// <param name="count">카운트</param>
        /// <returns>리스트</returns>
        public static List<Revenue> GetList(int count)
        {
            Random random = new Random(DateTime.Now.Millisecond);

            List<Revenue> list = new List<Revenue>();

            for(int i = 0; i < count; i++)
            {
                list.Add
                (
                    new Revenue
                    {
                        Country  = _countrArray[random.Next(0, 4)],
                        Category = _categoryArray[random.Next(0, 3)],
                        Amount   = random.Next(500, 5000)
                    }
                );
            }

            return list;
        }

        #endregion
    }
}

 

728x90

 

▶ MainForm.cs

using System.Windows.Forms;

using DevExpress.Data.Controls;
using DevExpress.Utils;
using DevExpress.XtraCharts;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;

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

        #region 생성자 - MainForm()

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

            #region 그리드 뷰를 설정한다.

            InitializeView(this.gridView, true, false, true, false, false);

            AddColumn(this.gridView, "Country" , "국가", 100, HorzAlignment.Near, false, null              , null   );
            AddColumn(this.gridView, "Category", "분야", 100, HorzAlignment.Near, false, null              , null   );
            AddColumn(this.gridView, "Amount"  , "금액", 100, HorzAlignment.Far , false, FormatType.Numeric, "#,##0");

            this.gridControl.DataSource = Revenue.GetList(1000);

            this.gridView.BestFitColumns();

            #endregion
            #region 차트 컨트롤을 설정한다.

            this.chartControl.Legend.AlignmentHorizontal            = LegendAlignmentHorizontal.Right;
            this.chartControl.Legend.AlignmentVertical              = LegendAlignmentVertical.Top;
            this.chartControl.SeriesTemplate.CrosshairLabelPattern  = "{S}: {V:C2}";
            this.chartControl.SeriesTemplate.SeriesPointsSorting    = SortingMode.Ascending;
            this.chartControl.SeriesTemplate.SeriesPointsSortingKey = SeriesPointKey.Argument;
            this.chartControl.SeriesTemplate.SeriesDataMember       = "Category";
            this.chartControl.SeriesTemplate.ArgumentDataMember     = "Country";
            this.chartControl.SeriesTemplate.SummaryFunction        = "SUM([Amount])";

            chartControl.SeriesTemplate.ValueDataMembers.AddRange("Amount");

            (this.chartControl.Diagram as XYDiagram).AxisY.Label.TextPattern = "{V:C0}";

            this.chartControl.DataSource = new ControlRowSource()
            {
                Control     = this.gridView,
                ControlRows = ControlRows.Selected
            };

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 뷰 초기화 하기 - InitializeView(gridView, multiSelect, allowFilter, allowSort, allowCellMerge, editable)

        /// <summary>
        /// 뷰 초기화 하기
        /// </summary>
        /// <param name="gridView">그리드 뷰</param>
        /// <param name="multiSelect">멀티 선택 여부</param>
        /// <param name="allowFilter">필터 허용 여부</param>
        /// <param name="allowSort">정렬 허용 여부</param>
        /// <param name="allowCellMerge">셀 병합 사용 여부</param>
        /// <param name="editable">편집 허용 여부</param>
        private void InitializeView(GridView gridView, bool multiSelect, bool allowFilter, bool allowSort, bool allowCellMerge, bool editable)
        {
            gridView.OptionsDetail.EnableMasterViewMode = false;
            gridView.OptionsSelection.MultiSelect       = multiSelect;
            gridView.OptionsSelection.MultiSelectMode   = GridMultiSelectMode.RowSelect;
            gridView.FocusRectStyle                     = DrawFocusRectStyle.None;

            // 그룹 패널
            gridView.OptionsView.ShowGroupPanel = false;

            // 행
            gridView.IndicatorWidth                         = 30;
            gridView.OptionsView.ShowIndicator              = true;
            gridView.OptionsView.EnableAppearanceEvenRow    = false;
            gridView.OptionsView.EnableAppearanceOddRow     = false;
            gridView.OptionsBehavior.KeepFocusedRowOnUpdate = false;
            gridView.OptionsNavigation.AutoFocusNewRow      = true;

            // 컬럼
            gridView.OptionsBehavior.AutoPopulateColumns      = false;
            gridView.OptionsView.ShowColumnHeaders            = true;
            gridView.OptionsView.ColumnAutoWidth              = false;
            gridView.OptionsMenu.EnableColumnMenu             = false;
            gridView.OptionsNavigation.EnterMoveNextColumn    = true;
            gridView.OptionsCustomization.AllowColumnMoving   = false;
            gridView.OptionsCustomization.AllowColumnResizing = true;
            gridView.OptionsCustomization.AllowFilter         = allowFilter;
            gridView.OptionsCustomization.AllowSort           = allowSort;

            // 셀
            gridView.OptionsView.ShowButtonMode                   = ShowButtonModeEnum.ShowForFocusedCell;
            gridView.OptionsView.AllowCellMerge                   = allowCellMerge;
            gridView.OptionsBehavior.EditorShowMode               = EditorShowMode.Default;
            gridView.OptionsBehavior.Editable                     = editable;
            gridView.OptionsSelection.EnableAppearanceFocusedCell = editable;
            gridView.OptionsSelection.InvertSelection             = false;
            gridView.OptionsHint.ShowCellHints                    = false;
            gridView.OptionsClipboard.CopyColumnHeaders           = DefaultBoolean.True;
        }

        #endregion
        #region 컬럼 추가하기 - AddColumn(gridView, columnName, caption, columnWidth, hAlignment, allowEdit, displayFormatType, displayFormatString)

        /// <summary>
        /// 컬럼 추가하기
        /// </summary>
        /// <param name="gridView">그리드 뷰</param>
        /// <param name="columnName">컬럼명</param>
        /// <param name="caption">제목</param>
        /// <param name="columnWidth">컬럼 너비</param>
        /// <param name="hAlignment">수평 정렬</param>
        /// <param name="allowEdit">편집 허용 여부</param>
        /// <param name="displayFormatType">디스플레이 포맷 타입</param>
        /// <param name="displayFormatString">디스플레이 포맷 문자열</param>
        /// <returns>그리드 컬럼</returns>
        private GridColumn AddColumn
        (
            GridView       gridView,
            string         columnName,
            string         caption,
            int            columnWidth,
            HorzAlignment  hAlignment,
            bool           allowEdit,
            FormatType?    displayFormatType,    
            string         displayFormatString
        )
        {
            GridColumn column = gridView.Columns.AddVisible(columnName, caption);

            column.Name                                    = columnName;
            column.Width                                   = columnWidth;
            column.AppearanceHeader.Options.UseTextOptions = true;
            column.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            column.AppearanceHeader.TextOptions.VAlignment = VertAlignment.Center;
            column.AppearanceCell.Options.UseTextOptions   = true;
            column.AppearanceCell.TextOptions.HAlignment   = hAlignment;
            column.AppearanceCell.TextOptions.VAlignment   = VertAlignment.Center;
            column.OptionsColumn.AllowEdit                 = allowEdit;

            if(displayFormatType.HasValue)
            {
                column.DisplayFormat.FormatType   = displayFormatType.Value;
                column.DisplayFormat.FormatString = displayFormatString;
            }

            return column;
        }

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

댓글을 달아 주세요