■ 커스텀 그리드 컨트롤을 사용하는 방법을 보여준다.
▶ DSBandedGridPainter.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 |
using System.Drawing; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Drawing; using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraGrid.Views.Grid.Drawing; using DevExpress.XtraGrid.Views.BandedGrid.Drawing; using DevExpress.XtraGrid.Views.Grid.ViewInfo; namespace TestProject { /// <summary> /// DS 밴드 그리드 페인터 /// </summary> public class DSBandedGridPainter : BandedGridPainter { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSBandedGridPainter(bandedGridView) /// <summary> /// 생성자 /// </summary> /// <param name="bandedGridView">밴드 그리드 뷰</param> public DSBandedGridPainter(BandedGridView bandedGridView) : base(bandedGridView) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 행 그리기 - DrawRows(e) /// <summary> /// 행 그리기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void DrawRows(GridViewDrawArgs e) { base.DrawRows(e); DrawEmptyAreaLines(e); } #endregion #region 비어있는 영역 선 그리기 - DrawEmptyAreaLines(e) /// <summary> /// 비어있는 영역 선 그리기 /// </summary> /// <param name="e">그리드 뷰 그리기 인자</param> protected virtual void DrawEmptyAreaLines(GridViewDrawArgs e) { GridViewRects gridViewRects = e.ViewInfo.ViewRects; Rectangle emptyRowRectangle = gridViewRects.EmptyRows; if(emptyRowRectangle.IsEmpty) { return; } Pen pen = SystemPens.ControlDark; if(View.OptionsView.ShowVertLines) { foreach(GridColumnInfoArgs gridColumnInfoArgs in e.ViewInfo.ColumnsInfo) { int x = gridColumnInfoArgs.Bounds.Right - 1; if((gridColumnInfoArgs.Column != null && gridColumnInfoArgs.Column.Fixed != FixedStyle.None) || ((gridViewRects.FixedLeft.IsEmpty || x > gridViewRects.FixedLeft.Right) && (gridViewRects.FixedRight.IsEmpty || x < gridViewRects.FixedRight.Left - 3))) { e.Graphics.DrawLine(pPen, x, emptyRowRectangle.Top, x, emptyRowRectangle.Bottom); } } if(!gridViewRects.FixedRight.IsEmpty) { e.Graphics.DrawLine ( pen, gridViewRects.FixedRight.Left - 1, emptyRowRectangle.Top, gridViewRects.FixedRight.Left - 1, emptyRowRectangle.Bottom ); } } if(View.OptionsView.ShowHorzLines) { int rowHeight = e.ViewInfo.MinRowHeight; for(int y = emptyRowRectangle.Top + rowHeight; y < emptyRowRectangle.Bottom; y += rowHeight) { e.Graphics.DrawLine(pPen, emptyRowRectangle.Left, y, gridViewRects.DataRectRight - 1, y); } } } #endregion } } |
▶ DSBandedGridView.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 |
using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.BandedGrid; namespace TestProject { /// <summary> /// DS 밴드 그리드 뷰 /// </summary> public class DSBandedGridView : BandedGridView { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 뷰 명칭 - ViewName /// <summary> /// 뷰 명칭 /// </summary> protected override string ViewName { get { return "DSBandedGridView"; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSBandedGridView() /// <summary> /// 생성자 /// </summary> public DSBandedGridView() : this(null) { } #endregion #region 생성자 - DSBandedGridView(gridControl) /// <summary> /// 생성자 /// </summary> /// <param name="gridControl">그리드 컨트롤</param> public DSBandedGridView(GridControl gridControl) : base(gridControl) { } #endregion } } |
▶ DSBandedGridViewInfoRegistrator.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 |
using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Registrator; namespace TestProject { /// <summary> /// DS 밴드 그리드 뷰 정보 등록자 /// </summary> public class DSBandedGridViewInfoRegistrator : BandedGridInfoRegistrator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 뷰 명칭 - ViewName /// <summary> /// 뷰 명칭 /// </summary> public override string ViewName { get { return "DSBandedGridView"; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 뷰 생성하기 - CreateView(gridControl) /// <summary> /// 뷰 생성하기 /// </summary> /// <param name="gridControl">그리드 컨트롤</param> /// <returns>베이스 뷰</returns> public override BaseView CreateView(GridControl gridControl) { return new DSBandedGridView(gridControl as GridControl); } #endregion #region 페인터 생성하기 - CreatePainter(baseView) /// <summary> /// 페인터 생성하기 /// </summary> /// <param name="baseView">베이스 뷰</param> /// <returns>베이스 뷰 페인터</returns> public override BaseViewPainter CreatePainter(BaseView baseView) { return new DSBandedGridPainter(baseView as DSBandedGridView); } #endregion } } |
▶ DSGridColumn.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 |
using System; using DevExpress.Utils.Serializing; using DevExpress.XtraGrid.Columns; namespace TestProject { /// <summary> /// DS 그리드 컬럼 /// </summary> public class DSGridColumn : GridColumn { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 커스텀 데이터 /// </summary> private string customData = string.Empty; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 커스텀 데이터 - CustomData /// <summary> /// 커스텀 데이터 /// </summary> [XtraSerializableProperty()] public string CustomData { get { return this.customData; } set { this.customData = value; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSGridColumn() /// <summary> /// 생성자 /// </summary> public DSGridColumn() { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 할당하기 - Assign(gridColumn) /// <summary> /// 할당하기 /// </summary> /// <param name="gridColumn">그리드 컬럼</param> protected override void Assign(GridColumn gridColumn) { base.Assign(gridColumn); if(gridColumn is DSGridColumn) { CustomData = (gridColumn as DSGridColumn).CustomData; } } #endregion } } |
▶ DSGridColumnCollection.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 |
using System; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Base; namespace TestProject { /// <summary> /// DS 그리드 컬럼 컬렉션 /// </summary> public class DSGridColumnCollection : GridColumnCollection { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSGridColumnCollection(columnView) /// <summary> /// 생성자 /// </summary> /// <param name="columnView">컬럼 뷰</param> public DSGridColumnCollection(ColumnView columnView) : base(columnView) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 컬럼 생성하기 - CreateColumn() /// <summary> /// 컬럼 생성하기 /// </summary> /// <returns>그리드 컬럼</returns> protected override GridColumn CreateColumn() { return new DSGridColumn(); } #endregion } } |
▶ DSGridControl.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 |
using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Registrator; namespace TestProject { /// <summary> /// DS 그리드 컨트롤 /// </summary> public class DSGridControl : GridControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 디폴트 뷰 생성하기 - CreateDefaultView() /// <summary> /// 디폴트 뷰 생성하기 /// </summary> /// <returns>베이스 뷰</returns> protected override BaseView CreateDefaultView() { return CreateView("DSGridView"); } #endregion #region 이용 가능한 뷰 코어 등록하기 - RegisterAvailableViewsCore(infoCollection) /// <summary> /// 이용 가능한 뷰 코어 등록하기 /// </summary> /// <param name="infoCollection">정보 컬렉션</param> protected override void RegisterAvailableViewsCore(InfoCollection infoCollection) { base.RegisterAvailableViewsCore(infoCollection); infoCollection.Add(new DSGridViewInfoRegistrator()); infoCollection.Add(new DSBandedGridViewInfoRegistrator()); } #endregion } } |
▶ DSGridHandler.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 |
using System.Windows.Forms; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.Handler; namespace TestProject { /// <summary> /// DS 그리드 핸들러 /// </summary> public class DSGridHandler : GridHandler { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSGridHandler(gridView) /// <summary> /// 생성자 /// </summary> /// <param name="gridView">그리드 뷰</param> public DSGridHandler(GridView gridView) : base(gridView) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected //////////////////////////////////////////////////////////////////////////////// Function #region 키 다운시 처리하기 - OnKeyDown(e) /// <summary> /// 키 다운시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if(e.KeyData == Keys.Delete && View.State == GridState.Normal) { View.DeleteRow(View.FocusedRowHandle); } } #endregion } } |
▶ DSGridPainter.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 |
using System.Drawing; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Drawing; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.Drawing; using DevExpress.XtraGrid.Views.Grid.ViewInfo; namespace TestProject { /// <summary> /// DS 그리드 페인터 /// </summary> public class DSGridPainter : GridPainter { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSGridPainter(gridView) /// <summary> /// 생성자 /// </summary> /// <param name="gridView">그리드 뷰</param> public DSGridPainter(GridView gridView) : base(gridView) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 정상 행 그리기 - DrawRegularRow(e, gridDataRowInfo) /// <summary> /// 정상 행 그리기 /// </summary> /// <param name="e">이벤트 인자</param> /// <param name="gridDataRowInfo">그리드 데이타 행 정보</param> protected override void DrawRegularRow(GridViewDrawArgs e, GridDataRowInfo gridDataRowInfo) { base.DrawRegularRow(e, gridDataRowInfo); if(gridDataRowInfo.IsMasterRow && gridDataRowInfo.MasterRowExpanded) { GridView detailGridView = View.GetDetailView(gridDataRowInfo.RowHandle, 0) as GridView; if(detailGridView == null) { return; } GridCellInfo gridCellInfo = gridDataRowInfo.Cells[View.VisibleColumns[0]]; int center; if(gridCellInfo != null) { center = gridCellInfo.CellButtonRect.Left + gridCellInfo.CellButtonRect.Width / 2; } else { center = gridDataRowInfo.DetailIndentBounds.Left + gridDataRowInfo.DetailIndentBounds.Width / 2 ; } GridViewInfo gridViewInfo = detailGridView.GetViewInfo() as GridViewInfo; int level = 0; Point startPoint; Point endPoint; foreach(GridRowInfo gridRowInfo in gridViewInfo.RowsInfo) { if(detailGridView.IsRowVisible(gridRowInfo.RowHandle) != RowVisibleState.Visible) { continue; } level = gridRowInfo.Bounds.Top + gridRowInfo.Bounds.Height / 2; startPoint = new Point(center, level); endPoint = new Point(gridDataRowInfo.DetailIndentBounds.Right, level); e.Graphics.DrawLine(Pens.Black, startPoint, endPoint); } startPoint = new Point(center, gridDataRowInfo.DetailIndentBounds.Top); endPoint = new Point(center, level); e.Graphics.DrawLine(Pens.Black, startPoint, endPoint); } } #endregion #region 행 그리기 - DrawRows(e) /// <summary> /// 행 그리기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void DrawRows(GridViewDrawArgs e) { base.DrawRows(e); DrawEmptyAreaLines(e); } #endregion #region 비어있는 영역 선 그리기 - DrawEmptyAreaLines(e) /// <summary> /// 비어있는 영역 선 그리기 /// </summary> /// <param name="e">그리드 뷰 그리기 인자</param> protected virtual void DrawEmptyAreaLines(GridViewDrawArgs e) { GridViewRects gridViewRects = e.ViewInfo.ViewRects; Rectangle emptyRowRectangle = gridViewRects.EmptyRows; if(emptyRowRectangle.IsEmpty) { return; } Pen pen = SystemPens.ControlDark; if(View.OptionsView.ShowVertLines) { foreach(GridColumnInfoArgs gridColumnInfoArgs in e.ViewInfo.ColumnsInfo) { int x = gridColumnInfoArgs.Bounds.Right - 1; if((gridColumnInfoArgs.Column != null && gridColumnInfoArgs.Column.Fixed != FixedStyle.None) || ((gridViewRects.FixedLeft.IsEmpty || x > gridViewRects.FixedLeft.Right) && (gridViewRects.FixedRight.IsEmpty || x < gridViewRects.FixedRight.Left - 3))) { e.Graphics.DrawLine(pen, x, emptyRowRectangle.Top, x, emptyRowRectangle.Bottom); } } if(!gridViewRects.FixedRight.IsEmpty) { e.Graphics.DrawLine ( pen, gridViewRects.FixedRight.Left - 1, emptyRowRectangle.Top, gridViewRects.FixedRight.Left - 1, emptyRowRectangle.Bottom ); } } if(View.OptionsView.ShowHorzLines) { int rowHeight = e.ViewInfo.MinRowHeight; for(int y = emptyRowRectangle.Top + rowHeight; y < emptyRowRectangle.Bottom; y += rowHeight) { e.Graphics.DrawLine(pen, emptyRowRectangle.Left, y, gridViewRects.DataRectRight - 1, y); } } } #endregion } } |
▶ DSGridView.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 |
using System.Drawing; using DevExpress.Utils.Drawing; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Drawing; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Printing; namespace TestProject { /// <summary> /// DS 그리드 뷰 /// </summary> public class DSGridView : GridView { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 뷰 명칭 - ViewName /// <summary> /// 뷰 명칭 /// </summary> protected override string ViewName { get { return "DSGridView"; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSGridView() /// <summary> /// 생성자 /// </summary> public DSGridView() : this(null) { } #endregion #region 생성자 - DSGridView(gridControl) /// <summary> /// 생성자 /// </summary> /// <param name="gridControl">그리드 컨트롤</param> public DSGridView(GridControl gridControl) : base(gridControl) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region 커스텀 셀 그리기 인자 구하기 - GetCustomDrawCellArgs(graphicsCache, rectangle, gridColumn) /// <summary> /// 커스텀 셀 그리기 인자 구하기 /// </summary> /// <param name="graphicsCache">그래픽스 캐시</param> /// <param name="rectangle">사각형</param> /// <param name="gridColumn">그리드 컬럼</param> /// <returns>꼬리말 셀 커스텀 그리기 이벤트 인자</returns> public FooterCellCustomDrawEventArgs GetCustomDrawCellArgs(GraphicsCache graphicsCache, Rectangle rectangle, GridColumn gridColumn) { GridFooterCellInfoArgs gridFooterCellInfoArgs = new GridFooterCellInfoArgs(graphicsCache); gridFooterCellInfoArgs.Bounds = new Rectangle(new Point(0, 0), rectangle.Size); FooterCellCustomDrawEventArgs e = new FooterCellCustomDrawEventArgs(graphicsCache, -1, gridColumn, null, gridFooterCellInfoArgs); e.Handled = true; RaiseCustomDrawFooterCell(e); return e; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 컬럼 컬렉션 생성하기 - CreateColumnCollection() /// <summary> /// 컬럼 컬렉션 생성하기 /// </summary> /// <returns>그리드 컬럼 컬렉션</returns> protected override GridColumnCollection CreateColumnCollection() { return new DSGridColumnCollection(this); } #endregion #region 인쇄 정보 인스턴스 생성하기 - CreatePrintInfoInstance(e) /// <summary> /// 인쇄 정보 인스턴스 생성하기 /// </summary> /// <param name="e">이벤트 인자</param> /// <returns>베이스 뷰 인쇄 정보</returns> protected override BaseViewPrintInfo CreatePrintInfoInstance(PrintInfoArgs e) { return new DSGridViewPrintInfo(e); } #endregion } } |
▶ DSGridViewInfo.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 |
using System.Drawing; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; namespace TestProject { /// <summary> /// DS 그리드 뷰 정보 /// </summary> public class DSGridViewInfo : GridViewInfo { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSGridViewInfo(gridView) /// <summary> /// 생성자 /// </summary> /// <param name="gridView">그리드 뷰</param> public DSGridViewInfo(GridView gridView) : base(gridView) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 행 높이 계산하기 - CalcRowHeight(graphics, rowHandle, minimumHeight, level, useCache, gridColumnsInfo) /// <summary> /// 행 높이 계산하기 /// </summary> /// <param name="graphics">그래픽스</param> /// <param name="rowHandle">행 핸들</param> /// <param name="minimumHeight">최소 높이</param> /// <param name="level">레벨</param> /// <param name="useCache">캐시 사용 여부</param> /// <param name="gridColumnsInfo">그리드 컬럼 정보</param> /// <returns>행 높이</returns> public override int CalcRowHeight(Graphics graphics, int rowHandle, int minimumHeight, int level, bool useCache, GridColumnsInfo gridColumnsInfo) { return base.CalcRowHeight(graphics, rowHandle, minimumHeight, level, useCache, gridColumnsInfo); } #endregion } } |
▶ DSGridViewInfoRegistrator.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 |
using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Views.Base.Handler; using DevExpress.XtraGrid.Views.Base.ViewInfo; using DevExpress.XtraGrid.Registrator; namespace TestProject { /// <summary> /// DS 그리드 뷰 정보 등록자 /// </summary> public class DSGridViewInfoRegistrator : GridInfoRegistrator { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 뷰 명칭 - ViewName /// <summary> /// 뷰 명칭 /// </summary> public override string ViewName { get { return "DSGridView"; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 뷰 생성하기 - CreateView(gridControl) /// <summary> /// 뷰 생성하기 /// </summary> /// <param name="gridControl">그리드 컨트롤</param> /// <returns>베이스 뷰</returns> public override BaseView CreateView(GridControl gridControl) { return new DSGridView(gridControl as GridControl); } #endregion #region 페인터 생성하기 - CreatePainter(baseView) /// <summary> /// 페인터 생성하기 /// </summary> /// <param name="baseView">베이스 뷰</param> /// <returns>베이스 뷰 페인터</returns> public override BaseViewPainter CreatePainter(BaseView baseView) { return new DSGridPainter(baseView as DSGridView); } #endregion #region 뷰 정보 생성하기 - CreateViewInfo(baseView) /// <summary> /// 뷰 정보 생성하기 /// </summary> /// <param name="baseView">베이스 뷰</param> /// <returns>베이스 뷰 정보</returns> public override BaseViewInfo CreateViewInfo(BaseView baseView) { return new DSGridViewInfo(baseView as DSGridView); } #endregion #region 핸들러 생성하기 - CreateHandler(baseView) /// <summary> /// 핸들러 생성하기 /// </summary> /// <param name="baseView">베이스 뷰</param> /// <returns>베이스 뷰 핸들러</returns> public override BaseViewHandler CreateHandler(BaseView baseView) { return new DSGridHandler(baseView as DSGridView); } #endregion } } |
▶ DSGridViewPrintInfo.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 |
using System.Drawing; using DevExpress.Data; using DevExpress.Utils.Drawing; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Printing; using DevExpress.XtraPrinting; namespace TestProject { /// <summary> /// DS 그리드 뷰 인쇄 정보 /// </summary> public class DSGridViewPrintInfo : GridViewPrintInfo { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 꼬리말 패널 높이 - FooterPanelHeight /// <summary> /// 꼬리말 패널 높이 /// </summary> public int FooterPanelHeight { get { return CalcStyleHeight(AppearancePrint.FooterPanel) + 4; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DSGridViewPrintInfo(printInfoArgs) /// <summary> /// 생성자 /// </summary> /// <param name="printInfoArgs">인쇄 정보 인자</param> public DSGridViewPrintInfo(PrintInfoArgs printInfoArgs) : base(printInfoArgs) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 꼬리말 패널 인쇄하기 - PrintFooterPanel(brickGraphics) /// <summary> /// 꼬리말 패널 인쇄하기 /// </summary> /// <param name="brickGraphics">브릭 그래픽스</param> public override void PrintFooterPanel(IBrickGraphics brickGraphics) { base.PrintFooterPanel(brickGraphics); CustomDrawFooterCells(brickGraphics); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 이미지 브릭 구하기 - GetImageBrick(printColumnInfo, rectangle, text) /// <summary> /// 이미지 브릭 구하기 /// </summary> /// <param name="printColumnInfo">인쇄 컬럼 정보</param> /// <param name="rectangle">사각형</param> /// <param name="text">텍스트</param> /// <returns>이미지 브릭</returns> private ImageBrick GetImageBrick(PrintColumnInfo printColumnInfo, Rectangle rectangle, out string text) { Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height); GraphicsCache graphicsCache = new GraphicsCache(Graphics.FromImage(bitmap)); FooterCellCustomDrawEventArgs e = (View as DSGridView).GetCustomDrawCellArgs(graphicsCache, rectangle, printColumnInfo.Column); text = e.Info.DisplayText; if(!e.Handled) { return null; } BorderSide borderSide = e.Appearance.Options.UseBorderColor ? BorderSide.All : BorderSide.None; ImageBrick imageBrick = new ImageBrick(borderSide, 1, e.Appearance.BorderColor, e.Appearance.BackColor); imageBrick.Rect = rectangle; imageBrick.Image = bitmap; return imageBrick; } #endregion #region 커스텀 꼬리말 셀 그리기 - CustomDrawFooterCells(brickGraphics) /// <summary> /// 커스텀 꼬리말 셀 그리기 /// </summary> /// <param name="brickGraphics">브릭 그래픽스</param> private void CustomDrawFooterCells(IBrickGraphics brickGraphics) { if(!View.OptionsPrint.PrintFooter) { return; } foreach(PrintColumnInfo printColumnInfo in Columns) { if(printColumnInfo.Column.SummaryItem.SummaryType == SummaryItemType.None) { continue; } Rectangle rectangle = Rectangle.Empty; rectangle.X = printColumnInfo.Bounds.X + Indent; rectangle.Y = printColumnInfo.RowIndex * FooterPanelHeight + 2 + Y; rectangle.Width = printColumnInfo.Bounds.Width; rectangle.Height = FooterPanelHeight * printColumnInfo.RowCount; rectangle.X -= Indent; rectangle.Y -= rectangle.Height; string text = string.Empty; ImageBrick imageBrick = GetImageBrick(printColumnInfo, rectangle, out text); if(imageBrick != null) { brickGraphics.DrawBrick(imageBrick, imageBrick.Rect); } } } #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 |
using System; using System.Data; using System.Drawing; using System.Windows.Forms; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.gridView.Appearance.HeaderPanel.Font = new Font("나눔고딕코딩", 12f); this.gridView.Appearance.Row.Font = new Font("나눔고딕코딩", 12f); } #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.gridControl.DataSource = GetList(); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 리스트 구하기 - GetList() /// <summary> /// 리스트 구하기 /// </summary> /// <returns>데이터 테이블</returns> private DataTable GetList() { DataTable table = new DataTable(); table.Columns.Add("a", typeof(string)); table.Columns.Add("b", typeof(string)); DataRow row; row = table.NewRow(); row["a"] = "1"; row["b"] = "2"; table.Rows.Add(row); row = table.NewRow(); row["a"] = "3"; row["b"] = "4"; table.Rows.Add(row); return table; } #endregion } } |