将查询结果DataTable的某字段赋给ComboBox的DisplayMember和ValueMember
程序员文章站
2022-04-12 11:49:29
...
将DataTable的某字段赋给ComboBox的DisplayMember和ValueMember
//构造查询字符串
string sqlOrg = "select F_ID,F_OrganName from T_LIS_Base_Org";
//根据查询字符串返回一个DataTable
DataTable dtOrg = DirectAceDB.GetDataTableBySql(sqlOrg);
//设置下拉列表
cmbOrg.DataSource = dtOrg;
cmbOrg.DisplayMember = "F_OrganName";
cmbOrg.ValueMember = "F_ID";
//用下面的方法也能设置下拉的显示值跟真实值
//cmbOrg.DisplayMember = dtOrg.Columns["F_OrganName"].ToString();
//cmbOrg.ValueMember = dtOrg.Columns["F_ID"].ToString();
上一篇: vue 待办事项案列