I am using Entity Framework 6 to model a list of clients from a database. I am binding the collection successfully to a listbox. What I can't figure out how to do is to use multiple fields from the object to bind to the DisplayMember
property of the Windows Form ListBox.
This works ...
myLsiTBox.DataSource = context.Clients.ToList();
myLsiTBox.DisplayMember = "CompanyName";
myLsiTBox.ValueMember = "id";
This fails ...
myLsiTBox.DataSource = context.Clients.ToList();
myLsiTBox.DisplayMember = "CompanyName" + "-" + "LastName" + " - " + "FirstName";
myLsiTBox.ValueMember = "id";
How do I go about displaying the content from multiple fields in the ListBox?
If this was your client:
You could make a ClientViewModel and then bind the list box data source to the list of ClientViewModels and set the DisplayMember to "FullDetails".
..or just add the FullDetails property to the orignal Client class if you can.