ComboBoxEdit也是DevExpress winform控件中经常使用的一个,我们在使用的过程中可能有时需要对ComboBoxEdit控件进行数据绑定,而ComboBoxEdit控件不像 LookUpEdit控件拥有DataSource属性,可以直接绑定一个数据集。 下面我们使用 ComboBoxEdit的comboBoxEdit1.Properties.Items.Add(object item)方法来实现数据绑定.
1.先用GetAreaDataTable方法返回一个DataTable,代码如下:
public static DataTable GetAreaDataTable() { string sqlStr = "select BMMC from usiCLB where BMLID=3"; DataBase db = new DataBase(); DataTable dt = db.GetDataTable(sqlStr); return dt; }
2.然后将数据循环添加到ComboBoxEdit中,代码如下:
private void LoadComboBoxEdit() { this.comboBoxEdit1.Properties.NullText = "请选择..."; DataTable dt = UserInfo.GetAreaDataTable(); for (int i = 0; i < dt.Rows.Count; i++) { comboBoxEdit1.Properties.Items.Add(dt.Rows[i]["BMMC"].ToString()); } }