0

我有一个组合框cboPrePartNum

  • 数据源 - prepartBindingSource
  • 显示成员 - PrePartNum
  • 价值成员 - PrePartNum
  • 选定值 - engordbindingsource - prepartnum

当表单加载时运行:

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; }
    }
}
4

2 回答 2

1

您不需要在组合框中设置 Selected Value。您可以像下面的代码一样获取和设置选定的项目,

 cboPrePartNum.SelectedItem = <PartPrevioustype of object>;

 <PartPrevioustype of object> = cboPrePartNum.SelectedItem;
于 2013-06-18T04:26:13.580 回答
0

你应该设置

cboPrePartNum.DataTextField  

cboPrePartNum.DataValueField

然后它将正确绑定

于 2013-06-18T07:24:50.993 回答