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

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

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

using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Data;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraTreeList.StyleFormatConditions;

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

        #region 생성자 - MainForm()

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

            Load += Form_Load;
        }

        #endregion

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

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            TreeList treeList = new TreeList();

            treeList.Parent = this;
            treeList.Dock   = DockStyle.Fill; 

            treeList.RowHeight                              = 25;
            treeList.OptionsView.AutoWidth                  = false;
            treeList.OptionsView.AllowHtmlDrawHeaders       = true;
            treeList.OptionsView.ShowSummaryFooter          = true;
            treeList.OptionsBehavior.PopulateServiceColumns = true;
            treeList.KeyFieldName                           = "ID";
            treeList.ParentFieldName                        = "RegionID";

            treeList.DataSource = SalesData.GetSalesDataList();

            TreeListColumn regionColumn             = treeList.Columns["Region"            ];
            TreeListColumn marchSalesColumn         = treeList.Columns["MarchSales"        ];
            TreeListColumn septemberSalesColumn     = treeList.Columns["SeptemberSales"    ];
            TreeListColumn marchSalesPrevColumn     = treeList.Columns["MarchSalesPrev"    ];
            TreeListColumn septemberSalesPrevColumn = treeList.Columns["SeptemberSalesPrev"];
            TreeListColumn marketShareColumn        = treeList.Columns["MarketShare"       ];

            treeList.Columns[treeList.KeyFieldName   ].Visible = false;
            treeList.Columns[treeList.ParentFieldName].Visible = false;

            regionColumn.OptionsColumn.ReadOnly = true;
            regionColumn.SortIndex              = 0;

            marchSalesColumn.SummaryFooter          = SummaryItemType.Sum;
            marchSalesColumn.SummaryFooterStrFormat = "Total={0:c0}";
            marchSalesColumn.AllNodesSummary        = false;

            septemberSalesColumn.SummaryFooter          = SummaryItemType.Sum;
            septemberSalesColumn.SummaryFooterStrFormat = "Total={0:c0}";
            septemberSalesColumn.AllNodesSummary        = false;

            marchSalesPrevColumn.Caption             = "<i>Previous <b>March</b> Sales</i>";
            marchSalesPrevColumn.AppearanceCell.Font = new Font(marchSalesPrevColumn.AppearanceCell.Font, FontStyle.Italic);

            septemberSalesPrevColumn.Caption             = "<i>Previous <b>September</b> Sales</i>";
            septemberSalesPrevColumn.AppearanceCell.Font = new Font(septemberSalesPrevColumn.AppearanceCell.Font, FontStyle.Italic);

            TreeListColumn fromPrevMarchChangeColumn = treeList.Columns.AddField("FromPrevMarchChange");

            fromPrevMarchChangeColumn.Caption                               = "Change from prev March";
            fromPrevMarchChangeColumn.UnboundType                           = UnboundColumnType.Decimal;
            fromPrevMarchChangeColumn.UnboundExpression                     = "[MarchSales]-[MarchSalesPrev]";
            fromPrevMarchChangeColumn.OptionsColumn.ShowInCustomizationForm = false;

            TreeListColumn fromPrevSepChangeColumn = treeList.Columns.AddField("FromPrevSepChange");

            fromPrevSepChangeColumn.Caption                               = "Change from prev September";
            fromPrevSepChangeColumn.UnboundType                           = UnboundColumnType.Decimal;
            fromPrevSepChangeColumn.UnboundExpression                     = "[SeptemberSales]-[SeptemberSalesPrev]";
            fromPrevSepChangeColumn.OptionsColumn.ShowInCustomizationForm = false;

            treeList.ActiveFilterString = "[MarchSales] > 10000";

            RepositoryItemSpinEdit repositoryItemSpinEdit = new RepositoryItemSpinEdit();

            repositoryItemSpinEdit.DisplayFormat.FormatType   = FormatType.Numeric;
            repositoryItemSpinEdit.DisplayFormat.FormatString = "c0";

            treeList.RepositoryItems.Add(repositoryItemSpinEdit);

            marchSalesColumn.ColumnEdit         = repositoryItemSpinEdit;
            marchSalesPrevColumn.ColumnEdit     = repositoryItemSpinEdit;
            septemberSalesColumn.ColumnEdit     = repositoryItemSpinEdit;
            septemberSalesPrevColumn.ColumnEdit = repositoryItemSpinEdit;

            TreeListFormatRule rule1 = new TreeListFormatRule();

            rule1.Rule          = GetFormatConditionRuleIconSet();
            rule1.Column        = fromPrevMarchChangeColumn;
            rule1.ColumnApplyTo = marchSalesColumn;

            treeList.FormatRules.Add(rule1);

            TreeListFormatRule rule2 = new TreeListFormatRule();

            rule2.Rule          = GetFormatConditionRuleIconSet();
            rule2.Column        = fromPrevSepChangeColumn;
            rule2.ColumnApplyTo = septemberSalesColumn;

            treeList.FormatRules.Add(rule2);

            TreeListNode node1 = treeList.FindNodeByFieldValue("Region", "North America");

            treeList.FocusedNode = node1;

            node1.Expanded = true;

            TreeListNode node2 = treeList.FindNodeByKeyID(32); //Node 'Asia'

            node2.Expand();

            BeginInvoke
            (
                new MethodInvoker
                (
                    delegate
                    {
                        treeList.BestFitColumns();
                    }
                )
            );
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 포맷 조건부 규칙 아이콘 세트 구하기 - GetFormatConditionRuleIconSet()

        /// <summary>
        /// 포맷 조건 규칙 아이콘 세트 구하기
        /// </summary>
        /// <returns>포맷 조건부 규칙 아이콘 세트</returns>
        private FormatConditionRuleIconSet GetFormatConditionRuleIconSet()
        {
            FormatConditionRuleIconSet ruleIconSet = new FormatConditionRuleIconSet();

            FormatConditionIconSet iconSet = new FormatConditionIconSet();

            iconSet.ValueType = FormatConditionValueType.Number;

            ruleIconSet.IconSet = iconSet;

            FormatConditionIconSetIcon icon1 = new FormatConditionIconSetIcon();
            FormatConditionIconSetIcon icon2 = new FormatConditionIconSetIcon();
            FormatConditionIconSetIcon icon3 = new FormatConditionIconSetIcon();

            icon1.PredefinedName = "Triangles3_3.png";
            icon2.PredefinedName = "Triangles3_2.png";
            icon3.PredefinedName = "Triangles3_1.png";

            icon1.Value           = Decimal.MinValue;
            icon1.ValueComparison = FormatConditionComparisonType.GreaterOrEqual;

            icon2.Value           = 0;
            icon2.ValueComparison = FormatConditionComparisonType.GreaterOrEqual;

            icon3.Value           = 0;
            icon3.ValueComparison = FormatConditionComparisonType.Greater;

            iconSet.Icons.Add(icon1);
            iconSet.Icons.Add(icon2);
            iconSet.Icons.Add(icon3);

            return ruleIconSet;
        }

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

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

[DEVEXPRESS/WINFORM] TreeList 클래스 : 커스텀 노드 사용하기  (0) 2020.05.16
[DEVEXPRESS/WINFORM] TreeList 클래스 : CustomUnboundColumnData 이벤트를 사용해 언바운드 컬럼 데이터 커스텀 설정하기  (0) 2020.05.16
[DEVEXPRESS/WINFORM] TreeListColumn 클래스 : UnboundExpression 속성을 사용해 언바운드 컬럼 데이터 설정하기  (0) 2020.05.16
[DEVEXPRESS/WINFORM] IVirtualTreeListData 인터페이스 : 트리 리스트 가상 모드 사용하기  (0) 2020.05.16
[DEVEXPRESS/WINFORM] TreeList 클래스 : ChildListFieldName 속성을 사용해 계층적 데이터 소스 사용하기  (0) 2020.05.16
[DEVEXPRESS/WINFORM] TreeList 클래스 : 실행시 트리 리스트 생성하기  (0) 2020.05.16
[DEVEXPRESS/WINFORM] PivotGridOptionsData 클래스 : CustomObjectConverter 속성을 사용해 객체 직렬화 커스텀 설정하기  (0) 2020.05.14
[DEVEXPRESS/WINFORM] PivotGridLocalizer 클래스 : Active 정적 속성을 사용해 불필요한 텍스트 숨기기  (0) 2020.05.14
[DEVEXPRESS/WINFORM] PivotGridControl 클래스 : FieldValueDisplayText 이벤트를 사용해 필드 값 디스플레이 텍스트 설정하기  (0) 2020.05.14
[DEVEXPRESS/WINFORM] PivotGridControl 클래스 : CustomCellDisplayText 이벤트를 사용해 셀 디스플레이 텍스트 커스텀 설정하기  (0) 2020.05.14
[DEVEXPRESS/WINFORM] PivotGridControl 클래스 : CustomDrawFieldValue 이벤트를 사용해 필드 값 헤더 모양 변경하기  (0) 2020.05.14
Posted by 사용자 icodebroker

댓글을 달아 주세요