c# - Need to 'BindingList' a member of a struct to a combobox -
good morning:
i have situation have 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 combobox on screen needs populated 'fullname' member can index of list access other information in it.
is possible? had members own separate bindinglist (i.e. not in struct), didn't seem right me.
i tried few different things (which didn't work), , did search here, nothing seemed close enough doing.
thank you, always. :) robert
do this, perhaps in form constructor :
combobox.valuemember = "employeeid"; combobox.displaymember = "fullname"; combobox.datasource = ei;
then setup selection change handler :
private void combobox_selectedindexchanged(object sender, eventargs e) { combobox cmb = (combobox)sender; var employeeid = (int)cmb.selectedvalue; // use value more info... }
Comments
Post a Comment