■ TreeList 클래스를 사용해 실행시 트리 리스트를 생성하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
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 } } |