troubleshooting Question

How to fill a combo box using the Entity Framework

Avatar of John500
John500Flag for United States of America asked on
Programming.NET ProgrammingC#
6 Comments1 Solution3786 ViewsLast Modified:
Hi,

I'm trying to fill a combo box using this code below that works:

  
private void LoadEntityComboBox()
        {
            var entities = (from e in Session.Entities
                            select new
                            {
                                ID = e.Entity1.PadRight(9) + e.Name,
                                
                            }).ToList();
            cb_Entity.DataSource = entities;

However, the results in the box not only include the curly brackets but they also include the title of 'ID' in front of the entity value.  So the output looks like this:

{ ID = 1        Entity_Value_1}
{ ID = 2        Entity_Value_2}
...

How can I do this so it looks like this:

1        Entity_Value_1
2        Entity_Value_2
...

I don't know if the combo box is capable of this or if there is some trick for formatting the EF output.  I would like to have the two columns in the row evenly spaced apart as in separate columns but maybe I need a ListView for this if a ListView has a drop-down property.

Thanks in advance !
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros