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、最终界面效果