我有一个组合框cboPrePartNum
:
当表单加载时,运行:
private void LoadComboBoxes()
{
List<PartPrevious> partPreviousList;
partPreviousList = PartDB.GetPartPreviousList();
cboPrePartNum.DataSource = partPreviousList;
cboPrePartNum.SelectedIndex = -1;
}
问题是表单加载时cboPrePartNum
组合框不会显示当前engordbindingsource.prepartnum
中的值。
这就是PartPrevious的样子:
public class PartPrevious
{
private string prepartnum;
private string prerevision;
private string prepartdescription;
public PartPrevious() { }
public string PrePartNum
{
get { return prepartnum; }
set { prepartnum = value; }
}
public string PreRevision
{
get { return prerevision; }
set { prerevision = value; }
}
public string PrePartdescription
{
get { return prepartdescription; }
set { prepartdescription = value; }
}
}
答案 0 :(得分:1)
您无需在组合框中设置“选定值”。您可以获取和设置所选项目,如下面的代码
cboPrePartNum.SelectedItem = <PartPrevioustype of object>;
<PartPrevioustype of object> = cboPrePartNum.SelectedItem;
答案 1 :(得分:0)
你应该设置
cboPrePartNum.DataTextField
和cboPrePartNum.DataValueField
然后它会正确绑定