첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

■ GridLookUpEdit 클래스 : 실행시 생성하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

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

    }

}

 

------------------------------------------------------------------------------------------------------------------------

728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요