■ PivotGridLocalizer 클래스의 Active 정적 속성을 사용해 불필요한 텍스트를 숨기는 방법을 보여준다.
▶ CustomLocalizer.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 |
using System; using DevExpress.XtraPivotGrid.Localization; namespace TestProject { /// <summary> /// 커스텀 로컬라이저 /// </summary> public class CustomLocalizer : PivotGridResLocalizer { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 지역화 문자열 구하기 - GetLocalizedString(id) /// <summary> /// 지역화 문자열 구하기 /// </summary> /// <param name="id">ID</param> /// <returns>지역화 문자열</returns> public override string GetLocalizedString(PivotGridStringId id) { if ( id == PivotGridStringId.DataHeadersCustomization || id == PivotGridStringId.ColumnHeadersCustomization || id == PivotGridStringId.FilterHeadersCustomization ) { return String.Empty; } return base.GetLocalizedString(id); } #endregion } } |
▶ 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 |
using System; using System.Data; using System.Drawing; using DevExpress.XtraEditors; using DevExpress.XtraPivotGrid; using DevExpress.XtraPivotGrid.Localization; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { PivotGridLocalizer.Active = new CustomLocalizer(); 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) { this.pivotGridControl.BeginUpdate(); this.pivotGridControl.DataSource = GetTable(20); this.pivotGridControl.Fields.Add("Type" , PivotArea.RowArea); this.pivotGridControl.Fields.Add("Product", PivotArea.RowArea); PivotGridField yearField = new PivotGridField("Date", PivotArea.RowArea); yearField.Name = "yearField"; yearField.Caption = yearField.Name; yearField.GroupInterval = PivotGroupInterval.DateYear; PivotGridField monthField = new PivotGridField("Date", PivotArea.RowArea); monthField.Name = "monthField"; monthField.Caption = monthField.Name; monthField.GroupInterval = PivotGroupInterval.DateMonth; pivotGridControl.Fields.AddRange(new PivotGridField[] { yearField, monthField }); pivotGridControl.Fields.Add("Flag", PivotArea.RowArea); this.pivotGridControl.CustomDrawFieldValue += pivotGridControl_CustomDrawFieldValue; this.pivotGridControl.Appearance.Lines.BackColor = Color.Transparent; this.pivotGridControl.EndUpdate(); } #endregion #region 피벗 그리드 컨트롤 필드 값 커스텀 그리기 - pivotGridControl_CustomDrawFieldValue(sender, e) /// <summary> /// 피벗 그리드 컨트롤 필드 값 커스텀 그리기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void pivotGridControl_CustomDrawFieldValue(object sender, PivotCustomDrawFieldValueEventArgs e) { if(e.Area == PivotArea.ColumnArea) { e.Graphics.FillRectangle(Brushes.White, e.Bounds); e.Handled = true; } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 테이블 구하기 - GetTable(rowCount) /// <summary> /// 테이블 구하기 /// </summary> /// <param name="rowCount">행 수</param> /// <returns>테이블</returns> private DataTable GetTable(int rowCount) { DataTable table = new DataTable(); table.Columns.Add("Type" , typeof(string )); table.Columns.Add("Product", typeof(string )); table.Columns.Add("Date" , typeof(DateTime)); table.Columns.Add("Flag" , typeof(bool )); for(int i = 0; i < rowCount; i++) { for(int j = 0; j < rowCount; j++) { table.Rows.Add ( new object[] { string.Format("Type {0}", i % 5), string.Format("Product {0}", i % 3), DateTime.Now.AddYears(j % 7).AddMonths(j % 9), i % 2 == 0 } ); } } return table; } #endregion } } |