ComboBoxEdit綁定數據源

搜索關鍵字:

"DataBindings" +"ComboBoxEdit"

在DevExpress官網上搜索,ComboBoxEdit綁定數據源的用法,結果沒有,告訴我應該使用LookUpEdit。所以決定自己實現一下,現在分享一下!

1、源代碼:Experiment4Control.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using DevExpress.XtraEditors;

 

namespace TutorialSLN

{

    public partial class Experiment4Control : DevExpress.XtraEditors.XtraForm

    {

        private DeptEntity itsDeptEntity;

        public Experiment4Control()

        {

            InitializeComponent();

            itsDeptEntity = new DeptEntity();

            itsDeptEntity.DeptName = "財務部";

            BindingComboEdit(this.comboBoxEdit1, itsDeptEntity, "DeptName");

        }

        void BindingComboEdit(ComboBoxEdit edit, object dataSource, string bindField)

        {

            try

            {

                edit.DataBindings.Clear();

                Binding b = new Binding("EditValue", dataSource, bindField);

                edit.DataBindings.Add(b);

            }

            catch (Exception ex)

            {

                //Msg.ShowException(ex);

                XtraMessageBox.Show(ex.ToString());

            }

        }

        private void ShowMsg()

        {

            XtraMessageBox.Show(itsDeptEntity.DeptName);

        }

 

        private void simpleButton1_Click(object sender, EventArgs e)

        {

            ShowMsg();

        }

 

    }

    public class DeptEntity

    {

        public string DeptName

        {

            get;

            set;

        }

    }

}

2、界面設置

3、最終界面效果

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章