让devexpress控件lookupedit绑定到实体属性

时间:2014-03-05 18:12:55   收藏:0   阅读:535

问题描述:

         想实现这么一个效果,lookupedit绑定到一个数据源datatable上,通过实体的一个属性设置lookupedit选定值,同时lookupedit选择值能反映到实体的属性上。

实现代码如下:

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;

using CimingHealthCare.Model;

using DevExpress.XtraEditors.Controls;

 

namespace LookUpEditUsage

{

    public partial class XFMTextEditLookupedit : DevExpress.XtraEditors.XtraForm

    {

        public XFMTextEditLookupedit()

        {

            InitializeComponent();

            PreIni();

            this.UC_Initialize();

            this.UC_Load();

        }

        private UserInfo _OT_SINGLE_CHECKINFOEntity = new UserInfo();

 

        ///<summary>

        ///个人基本信息

        ///</summary>

        public UserInfo OT_SINGLE_CHECKINFOEntity

        {

            get

            {

                return _OT_SINGLE_CHECKINFOEntity;

            }

            set

            {

                _OT_SINGLE_CHECKINFOEntity = value;

 

 

            }

        }

        public void UC_Initialize()

        {

            this.lookUpEdit1.Properties.DataSource = IniDataTable();

 

        }

        public void UC_Load()

        {

 

 

            this.textEdit1SglCheckID.DataBindings.Clear();

            this.lookUpEdit1.DataBindings.Clear();

 

 

            if (this._OT_SINGLE_CHECKINFOEntity !=null)

            {

                this.textEdit1SglCheckID.DataBindings.Add("EditValue",this._OT_SINGLE_CHECKINFOEntity, "Name");

                this.lookUpEdit1.DataBindings.Add("EditValue",this._OT_SINGLE_CHECKINFOEntity, "ID");

            }

            else

            {

                this.textEdit1SglCheckID.EditValue =null;

                this.lookUpEdit1.EditValue =null;

            }

        }

        private void PreIni()

        {

            LookUpColumnInfo col =null;

 

            col = new LookUpColumnInfo();

            col.Visible = true;

            col.FieldName ="FNAME";

            col.Caption = "工作空间";

            this.lookUpEdit1.Properties.Columns.Add(col);

 

            this.lookUpEdit1.Properties.DisplayMember ="FNAME";

            this.lookUpEdit1.Properties.NullText ="";

            this.lookUpEdit1.Properties.ValueMember ="FID";

        }

        private DataTable IniDataTable()

        {

            DataTable dataTable4Connection;

 

            dataTable4Connection = newDataTable();

            dataTable4Connection.Columns.Add(newDataColumn("FID",typeof(string)));

            dataTable4Connection.Columns.Add(newDataColumn("FNAME",typeof(string)));

 

            DataRow dr;

 

            dr = dataTable4Connection.NewRow();

            dr["FID"] = "1";

            dr["FNAME"] = "中原油田";

            dataTable4Connection.Rows.Add(dr);

 

            dr = dataTable4Connection.NewRow();

            dr["FID"] = "2";

            dr["FNAME"] = "新疆油田";

            dataTable4Connection.Rows.Add(dr);

 

            dataTable4Connection.AcceptChanges();

 

            return dataTable4Connection;

        }

 

        private void simpleButton1_Click(object sender, EventArgs e)

        {

            //MessageBox.Show(this.textEdit1SglCheckID.Text + " " + this.lookUpEdit1.EditValue.ToString());

            MessageBox.Show(this._OT_SINGLE_CHECKINFOEntity.Name +" " + _OT_SINGLE_CHECKINFOEntity.ID);

        }

    }

    public class UserInfo

    {

        public string Name

        {

            get;

            set;

        }

        public Int32 ID

        {

            get;

            set;

        }

    }

}

 

让devexpress控件lookupedit绑定到实体属性,布布扣,bubuko.com

原文:http://blog.csdn.net/cyberzhaohy/article/details/20489269

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!