需要 'BindingList' 结构成员到组合框

Need to 'BindingList' a member of a struct to a combobox

早上好:

我有这样的结构:

private struct EmployeeInfo
{
    public string LastName;
    public string FirstName;
    public string FullName { get; set; }
    public string Address;
    public string EmployeeID { get; set; }
}

private BindingList<EmployeeInfo> ei = new BindingList<EmployeeInfo>();

我在屏幕上有一个组合框,只需要由 'FullName' 成员填充,这样我就可以获得列表的索引以访问其中的其他信息。

这可能吗?最初我让成员有自己独立的 BindingList(即不在结构中),但我觉得这不对。

我尝试了一些不同的东西(没有用),我在这里进行了搜索,但似乎没有什么与我所做的相近。

谢谢你,一如既往。 :) 罗伯特

这样做,也许在表单构造函数中:

comboBox.ValueMember = "EmployeeID";
comboBox.DisplayMember = "FullName";
comboBox.DataSource = ei;

然后设置选择更改处理程序:

private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox cmb = (ComboBox)sender;
    var employeeId = (int)cmb.SelectedValue;
    // use the value to get more info...  
}