■ LookupEdit 클래스에서 콤보 박스 모드를 사용하는 방법을 보여준다.
▶ 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 |
using System; using System.Collections.Generic; using System.Windows.Forms; using DevExpress.Utils; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 레이블 컨트롤 딕셔너리 /// </summary> private Dictionary<LookUpEditBase, LabelControl> labelControlDictionary; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 레이블 컨트롤 딕셔너리 - LabelControlDictionary /// <summary> /// 레이블 컨트롤 딕셔너리 /// </summary> private Dictionary<LookUpEditBase, LabelControl> LabelControlDictionary { get { if(this.labelControlDictionary == null) { this.labelControlDictionary = new Dictionary<LookUpEditBase, LabelControl>(); this.labelControlDictionary.Add(lookUpEdit , lookupEditValueLabel); this.labelControlDictionary.Add(gridLookUpEdit, gridLookupEditValueLabel); } return this.labelControlDictionary; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Load += Form_Load; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 폼 로드시 처리하기 - Form_Load(sender, e) /// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_Load(object sender, EventArgs e) { #region 룩업 에디터를 설정한다. string[] colorArray = new string[] { "Yellow", "Red", "Green", "Black", "White" }; this.lookUpEdit.Properties.TextEditStyle = TextEditStyles.Standard; this.lookUpEdit.Properties.AcceptEditorTextAsNewValue = DefaultBoolean.Default; this.lookUpEdit.Properties.NullText = "(select or type value)"; this.lookUpEdit.Properties.DataSource = colorArray; #endregion #region 그리드 룩업 에디터를 설정한다. List<Product> productList = new List<Product> { new Product() { ProductName = "Chang" }, new Product() { ProductName = "Ipoh Coffee" }, new Product() { ProductName = "Ravioli Angelo" }, new Product() { ProductName = "Filo Mix" }, new Product() { ProductName = "Tunnbrod" }, new Product() { ProductName = "Konbu" }, new Product() { ProductName = "Boston Crab Meat" } }; this.gridLookUpEdit.Properties.TextEditStyle = TextEditStyles.Standard; this.gridLookUpEdit.Properties.AcceptEditorTextAsNewValue = DefaultBoolean.True; this.gridLookUpEdit.Properties.NullText = "(select or type value)"; this.gridLookUpEdit.Properties.ValueMember = "ProductName"; this.gridLookUpEdit.Properties.DisplayMember = this.gridLookUpEdit.Properties.ValueMember; this.gridLookUpEdit.Properties.DataSource = productList; #endregion #region 이벤트를 설정한다. this.lookUpEdit.EditValueChanged += lookUpEdit_EditValueChanged; this.gridLookUpEdit.ProcessNewValue += gridLookUpEdit_ProcessNewValue; this.gridLookUpEdit.EditValueChanged += lookUpEdit_EditValueChanged; #endregion } #endregion #region 룩업 에디터 편집 값 변경시 처리하기 - lookUpEdit_EditValueChanged(sender, e) /// <summary> /// 룩업 에디터 편집 값 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void lookUpEdit_EditValueChanged(object sender, EventArgs e) { LookUpEditBase lookupEditBase = sender as LookUpEditBase; if(lookupEditBase == null) { return; } LabelControl labelControl = LabelControlDictionary[lookupEditBase]; if(labelControl == null) { return; } if(lookupEditBase.EditValue == null) { labelControl.Text = "EditValue : null"; } else { labelControl.Text = "EditValue : " + lookupEditBase.EditValue.ToString(); } } #endregion #region 그리드 룩업 에디터 신규 값 처리하기 - gridLookUpEdit_ProcessNewValue(sender, e) /// <summary> /// 그리드 룩업 에디터 신규 값 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gridLookUpEdit_ProcessNewValue(object sender, ProcessNewValueEventArgs e) { GridLookUpEdit gridLookUpEdit = sender as GridLookUpEdit; if(e.DisplayValue == null) { return; } string newValue = e.DisplayValue.ToString(); if(newValue == string.Empty) { return; } if(MessageBox.Show(this, "'" + newValue + "' 항목을 목록에 추가하시겠습니까?", "CONFIRMATION", MessageBoxButtons.YesNo) == DialogResult.Yes) { List<Product> productList = gridLookUpEdit.Properties.DataSource as List<Product>; productList.Add(new Product { ProductName = newValue }); e.Handled = true; } } #endregion } } |