■ GridLookUpEdit 클래스에서 커스텀 컨트롤을 사용하는 방법을 보여준다.
▶ CustomRepositoryItemGridLookUpEdit.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 208 |
using System.Data; using System.Drawing; using DevExpress.XtraEditors.Drawing; using DevExpress.XtraEditors.Registrator; using DevExpress.XtraEditors.Repository; using DevExpress.XtraEditors.ViewInfo; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Grid; namespace TestProject { /// <summary> /// 커스텀 저장소 항목 그리드 룩업 에디터 /// </summary> [UserRepositoryItem("Register")] public class CustomRepositoryItemGridLookUpEdit : RepositoryItemGridLookUpEdit { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 에디터명 /// </summary> public const string EditorName = "CustomGridLookUpEdit"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 에디터 타입명 - EditorTypeName /// <summary> /// 에디터 타입명 /// </summary> public override string EditorTypeName { get { return EditorName; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - CustomRepositoryItemGridLookUpEdit() /// <summary> /// 생성자 /// </summary> static CustomRepositoryItemGridLookUpEdit() { Register(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - CustomRepositoryItemGridLookUpEdit() /// <summary> /// 생성자 /// </summary> public CustomRepositoryItemGridLookUpEdit() { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static #region 등록하기 - Register() /// <summary> /// 등록하기 /// </summary> public static void Register() { Image image = null; EditorRegistrationInfo.Default.Editors.Add ( new EditorClassInfo ( EditorName, typeof(CustomGridLookUpEdit), typeof(CustomRepositoryItemGridLookUpEdit), typeof(GridLookUpEditBaseViewInfo), new ButtonEditPainter(), true, image ) ); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Public #region 할당하기 - Assign(item) /// <summary> /// 할당하기 /// </summary> /// <param name="item">저장소 항목</param> public override void Assign(RepositoryItem item) { BeginUpdate(); try { base.Assign(item); CustomRepositoryItemGridLookUpEdit source = item as CustomRepositoryItemGridLookUpEdit; if(source == null) { return; } } finally { EndUpdate(); } } #endregion //////////////////////////////////////////////////////////////////////////////// Protected #region 로드시 처리하기 - OnLoaded() /// <summary> /// 로드시 처리하기 /// </summary> protected override void OnLoaded() { base.OnLoaded(); if(IsDesignMode) { return; } GridColumn idColumn = new GridColumn(); idColumn.FieldName = idColumn.Caption = "ID"; idColumn.VisibleIndex = 0; GridColumn nameColumn = new GridColumn(); nameColumn.FieldName = nameColumn.Caption = "Name"; nameColumn.VisibleIndex = 1; GridView gridView = View; gridView.Columns.Clear(); gridView.Columns.Add(idColumn ); gridView.Columns.Add(nameColumn); gridView.OptionsView.ShowGroupPanel = true; ValueMember = "ID"; DisplayMember = "Name"; DataSource = GetDataTable(); } #endregion //////////////////////////////////////////////////////////////////////////////// Protected #region 데이터 테이블 구하기 - GetDataTable() /// <summary> /// 데이터 테이블 구하기 /// </summary> /// <returns>데이터 테이블</returns> private DataTable GetDataTable() { DataTable table = new DataTable(); table.Columns.Add(new DataColumn("ID" , typeof(int ))); table.Columns.Add(new DataColumn("Name", typeof(string))); table.Rows.Add(new object[] { 0, "A" }); table.Rows.Add(new object[] { 1, "B" }); table.Rows.Add(new object[] { 2, "C" }); return table; } #endregion } } |
▶ CustomGridLookUpEdit.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 |
using System.ComponentModel; using DevExpress.XtraEditors; namespace TestProject { /// <summary> /// 커스텀 그리드 룩업 에디터 /// </summary> public class CustomGridLookUpEdit : GridLookUpEdit { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 에디터 타입명 - EditorTypeName /// <summary> /// 에디터 타입명 /// </summary> public override string EditorTypeName { get { return CustomRepositoryItemGridLookUpEdit.EditorName; } } #endregion #region 속성 - Properties /// <summary> /// 속성 /// </summary> [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public new CustomRepositoryItemGridLookUpEdit Properties { get { return base.Properties as CustomRepositoryItemGridLookUpEdit; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - CustomGridLookUpEdit() /// <summary> /// 생성자 /// </summary> static CustomGridLookUpEdit() { CustomRepositoryItemGridLookUpEdit.Register(); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Instance #region 생성자 - CustomGridLookUpEdit() /// <summary> /// 생성자 /// </summary> public CustomGridLookUpEdit() { } #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 |
using DevExpress.XtraEditors; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); } #endregion } } |