■ GridLookUpEdit 클래스에서 실행시 생성하는 방법을 보여준다.
▶ 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 |
using System.Data; using System.Data.OleDb; using System.Drawing; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Columns; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 연결 /// </summary> private OleDbConnection connection; /// <summary> /// 제품 뷰 /// </summary> private DataView productView; /// <summary> /// 주문 상세 뷰 /// </summary> private DataView orderDetailView; /// <summary> /// 그리드 룩업 에디트 /// </summary> private GridLookUpEdit gridLookUpEdit; /// <summary> /// 데이터 네비게이터 /// </summary> private DataNavigator dataNavigator; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=nwind.mdb"); #region 데이터를 설정한다. DataSet dataSet = new DataSet(); OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Products", this.connection); adapter.Fill(dataSet, "Products"); adapter = new OleDbDataAdapter("SELECT * FROM [Order Details]", this.connection); adapter.Fill(dataSet, "Order Details"); DataViewManager dataViewManager = new DataViewManager(dataSet); this.productView = dataViewManager.CreateDataView(dataSet.Tables["Products" ]); this.orderDetailView = dataViewManager.CreateDataView(dataSet.Tables["Order Details"]); #endregion #region 데이터 네비게이터를 설정한다. this.dataNavigator = new DataNavigator(); this.dataNavigator.Bounds = new Rectangle(50, 100, 300, 24); this.dataNavigator.Parent = this; this.dataNavigator.DataSource = orderDetailView; #endregion #region 그리드 룩업 에디터를 설정한다. this.gridLookUpEdit = new GridLookUpEdit(); this.gridLookUpEdit.Bounds = new Rectangle(50, 150, 300, 22); this.gridLookUpEdit.Parent = this; this.gridLookUpEdit.Properties.PopupView.OptionsBehavior.AutoPopulateColumns = false; this.gridLookUpEdit.Properties.ValueMember = "ProductID"; this.gridLookUpEdit.Properties.DisplayMember = "ProductName"; this.gridLookUpEdit.Properties.DataSource = productView; GridColumn productIDColumn = this.gridLookUpEdit.Properties.PopupView.Columns.AddField("ProductID"); productIDColumn.VisibleIndex = 0; productIDColumn.Caption = "Product ID"; GridColumn productNameColumn = this.gridLookUpEdit.Properties.PopupView.Columns.AddField("ProductName"); productNameColumn.VisibleIndex = 1; productNameColumn.Caption = "Product Name"; this.gridLookUpEdit.Properties.PopupFormWidth = 300; this.gridLookUpEdit.DataBindings.Add("EditValue", this.orderDetailView, "ProductID"); #endregion } #endregion } } |