I have a datasource which has three columns, FirstName, MiddleName, LastName in which I need to display these three fields into one Full Name. I need the full name to display in the combobox. This object also has a value member property that is a name id which needs to be set to the valuemember of the combo box. I can get one or the other to happen, but not both. I can combine the columns in a loop and bind the combobox to a List, which does not have the valuemember or I can have only one name, either first middle or last with the valuemember set.
Can anyone help?
Thank you. This worked. My combo box is know showing the full name of the person!!
gaxtell said:I'm not sure how to do the concatenation, which property do I set?
gaxtell said:Also, can the DisplayMember be set to the FullName property at design time?
If you add the column in code, such as in the combo's InitializeLayout event, then you need to set the DisplayMember property afterward, also in code.
Can you help me out with that? I'm not sure how to do the concatenation, which property do I set? This is what I have, but the text property is readonly so this won't work...
e.Row.Cells[
].Text.Trim();
Also, can the DisplayMember be set to the FullName property at design time? The FullName column does not show up as an available column when selecting the drop down.
I suggest using WinCombo for this approach, because it can contain multiple columns of data for each item in your list.
Add a new, unbound column to the WinCombo to represent your "full name" column. In the InitializeRow event of the combo, concatenate the FirstName, MiddleName, and LastName fields as desired and place the result in the cell belonging to your "full name" column. You can then use that "full name" column as the DisplayMember of the control. Your ID column would continue to be the ValueMember of the control.
If you don't want to display the full name column, you can hide it. Alternately, you could hide the other three columns instead, depending on what result you want.