Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone :)

I would like to thank everyone who has replied for your help.

Now this question is related to binding and populating of a combobox using Linq

Let me just say that before LINQ I would do the following

1. Create a class with a static list that was generically typed to the class itself.

This class would have two properties. An ID and a customer name The ID was the value member of the combobox and the customer name was th display member.

2. Use a datareader to populate the class.

3. Set the datasource of the combobox as the static list in the class and the ID and customername as valuemember and the displaymember.

No problems with that?! Right?

This used to work just great.

Until LINQ

Now I have used LINQ extensively for other purposes. I have not been able to understand how to do populate a combobox using LINQ.

I have a stored procedure that I am calling using LINQ as follows

CustomerDataContext db = new CustomerDataContext();
List <ListCustomerResult>ListCustomerResults = new db.ListCustomer().Tolist<ListCustomerResult>()

Now the question is how do I use ListCustomerResults for populating the combobox?

Any inputs or ideas are most welcome. If there is an alternate means of populating or binding a combobox using LINQ thne do let me know

Regards
Posted

1 solution

You have been doing it the hard way all along and there is no difference when using Linq.

combo.DisplayMember = "Name";
combo.ValueMember = "ID";
combo.DataSource = dataTable;

or

combo.DataSource = ListCustomerResults;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900