■ GridView 클래스에서 그리드 뷰 포커스 스타일을 설정하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 |
using System.Drawing; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Views.Grid; ... /// <summary> /// 포커스 스타일 열거형 /// </summary> public enum FocusStyle { /// <summary> /// 디폴트 /// </summary> Default, /// <summary> /// 행만 /// </summary> RowOnly, /// <summary> /// 셀만 /// </summary> CellOnly, /// <summary> /// 행과 컬럼 /// </summary> RowAndColumn, /// <summary> /// 셀 사각형만 /// </summary> CellRectangleOnly, /// <summary> /// 없음 /// </summary> None } ... private GridControl gridControl; private GridView gridView; ... this.gridView.FocusedColumnChanged += gridView_FocusedColumnChanged; ... /// <summary> /// 포커스 스타일 /// </summary> private FocusStyle focusStyle = FocusStyle.CellOnly; ... #region 그리드 뷰 포커스 컬럼 변경시 처리하기 - gridView_FocusedColumnChanged(sender, e) /// <summary> /// 그리드 뷰 포커스 컬럼 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gridView_FocusedColumnChanged(object sender, FocusedColumnChangedEventArgs e) { SetFocusedColumnAppearance(e.PrevFocusedColumn, e.FocusedColumn, this.focusStyle); } #endregion #region 그리드 뷰 포커스 스타일 설정하기 - SetGridViewFocusStyle(gridView, focusStyle) /// <summary> /// 그리드 뷰 포커스 스타일 설정하기 /// </summary> /// <param name="gridView">그리드 뷰</param> /// <param name="focusStyle">포커스 스타일</param> public void SetGridViewFocusStyle(GridView gridView, FocusStyle focusStyle) { this.focusStyle = focusStyle; switch(focusStyle) { case FocusStyle.Default : gridView.FocusRectStyle = DrawFocusRectStyle.CellFocus; gridView.OptionsSelection.EnableAppearanceFocusedCell = true; gridView.OptionsSelection.EnableAppearanceFocusedRow = true; gridView.OptionsSelection.InvertSelection = false; break; case FocusStyle.RowOnly : gridView.FocusRectStyle = DrawFocusRectStyle.RowFocus; gridView.OptionsSelection.EnableAppearanceFocusedRow = true; gridView.OptionsSelection.EnableAppearanceFocusedCell = false; gridView.OptionsSelection.InvertSelection = false; break; case FocusStyle.CellOnly : gridView.FocusRectStyle = DrawFocusRectStyle.CellFocus; gridView.OptionsSelection.EnableAppearanceFocusedCell = true; gridView.OptionsSelection.EnableAppearanceFocusedRow = true; gridView.OptionsSelection.InvertSelection = true; break; case FocusStyle.RowAndColumn : this.gridView.FocusRectStyle = DrawFocusRectStyle.CellFocus; this.gridView.OptionsSelection.EnableAppearanceFocusedCell = true; this.gridView.OptionsSelection.EnableAppearanceFocusedRow = true; this.gridView.OptionsSelection.InvertSelection = false; break; case FocusStyle.CellRectangleOnly : this.gridView.FocusRectStyle = DrawFocusRectStyle.CellFocus; this.gridView.OptionsSelection.EnableAppearanceFocusedCell = false; this.gridView.OptionsSelection.EnableAppearanceFocusedRow = false; this.gridView.OptionsSelection.InvertSelection = false; break; case FocusStyle.None: this.gridView.FocusRectStyle = DrawFocusRectStyle.None; this.gridView.OptionsSelection.EnableAppearanceFocusedCell = false; this.gridView.OptionsSelection.EnableAppearanceFocusedRow = false; this.gridView.OptionsSelection.InvertSelection = false; break; } SetFocusedColumnAppearance(null, gridView.FocusedColumn, focusStyle); } #endregion #region 포커스 컬럼 모양 설정하기 - SetFocusedColumnAppearance(previousColumn, currentColumn) /// <summary> /// 포커스 컬럼 모양 설정하기 /// </summary> /// <param name="previousColumn">이전 컬럼</param> /// <param name="currentColumn">현재 컬럼</param> private void SetFocusedColumnAppearance(GridColumn previousColumn, GridColumn currentColumn, FocusStyle focusStyle) { if(this.radioGroup.EditValue == null) { return; } if(previousColumn != null) { previousColumn.AppearanceCell.Reset(); } if(currentColumn != null) { if(focusStyle == FocusStyle.RowAndColumn) { currentColumn.AppearanceCell.BackColor = SystemColors.Highlight; currentColumn.AppearanceCell.ForeColor = SystemColors.HighlightText; } else { currentColumn.AppearanceCell.Reset(); } } } #endregion |