combobox databinding to display more than one values

I am developing a C#.net 2k5 winform app, I have a query to retrieve the data from database:

SELECT     staff_no + ' - ' + title + ' - ' + name + ' - ' + profession AS staff_combo, staff_id
FROM         staff
ORDER BY staff_id

I want to bind this staff_combo to my combobox1.display member, and staff to the combobox1.valuemember. I tried this line below, it didnt work, plz help:

this.staffTableAdapter.FillByStaffCombo( this.hPMDataSet.staff );




Answer this question

combobox databinding to display more than one values

  • redcodes

    I have another question concerning binding computed values into displayed value of combobox.

    My data is defined such way:

    interface IData {
    IDataPrimaryKey PrimaryKey { get; }
    string Label { get; }
    string Code { get; }
    }

    my datasource is IList<IData>.

    I need to display String.Format("{0} ({1})", data.Code, data.Label) as visible value in my combo
    box.

    How would I do this since I can't use DisplayMember, is there any event I can handle or any other solution

    Thanks.


  • Savindra

    can u plz demonstrate all steps take to display the staff_combo in my combobox

    someone suggest fill it manually with dataReader ,i am confused...



  • PrashanthBlog

    try this

    combobox1.DataSource = ds; //datasource
    combobox1.DisplayMember = "staff.staff_combo";
    combobox1.ValueMember = "staff.staff_id";



  • combobox databinding to display more than one values