如何获得使用foreach循环创建的组合框的值成员?它不显示值成员。
我的代码如下:
DataSet dsLoadWorkHourId = new DataSet();
dsLoadWorkHourId = Workhour.LoadWorkId();
foreach (DataRow row in dsLoadWorkHourId.Tables[0].Rows)
{
cmbWorkHourId.Items.Add(row["SHIFT"].ToString());
}
答案 0 :(得分:2)
你应该这样做
DataSet dsLoadWorkHourId = new DataSet();
dsLoadWorkHourId = Workhour.LoadWorkId();
cmbWorkHourID.DataSource = dsLoadWorkHourId.Tables[0]
cmbWorkHourID.DisplayMember = "SHIFT";
cmbWorkHourID.ValueMember = "SHIFTID"; //Use the ID column name here
如果要将ID显示为显示成员而不是
DataSet dsLoadWorkHourId = new DataSet();
dsLoadWorkHourId = Workhour.LoadWorkId();
cmbWorkHourID.DataSource = dsLoadWorkHourId.Tables[0]
cmbWorkHourID.DisplayMember = "SHIFTID"; //use the ID column name here
cmbWorkHourID.ValueMember = "SHIFTID"; //Use the ID column name here