0

Good Morning:

I have a situation where I have this struct:

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>();

I have a ComboBox on the screen that needs to be populated only by the 'FullName' member so I can get the index of the List to access the other information in it.

Is this possible? Originally I had the members with their own separate BindingList (i.e. not in a struct), but it didn't seem right to me.

I tried a few different things (which didn't work), and I did a search here, but nothing seemed close enough to what I was doing.

Thank you, as always. :) Robert

Eugene Podskal
  • 10,270
  • 5
  • 31
  • 53

1 Answers1

1

Do this, perhaps in form constructor :

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

Then setup a selection change handler :

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