?
Solved

How do I loop through and display the content of an entity list using a while loop.

Posted on 2015-01-09
4
Medium Priority
?
93 Views
Last Modified: 2015-03-03
How do I loop through and display the formatted content of an entity list using a while loop.
There's more than one item in sample below.

For example:
NLAMEMEntities2 oe = new NLAMEMEntities2();
 oe.Test5.ToList().Where(x => x.t5ID == int.Parse(TextBox4.Text.ToString())).First();

Open in new window

0
Comment
Question by:bmanmike39
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 1000 total points
ID: 40541699
I have sample code where data is uploaded to a combobox based on data from Entity Framework Table:
 
// CLASS LEVEL DATA VARIABLE
WSCGSoftwareEntities db = new WSCGSoftwareEntities();

 ' LOAD CUSTOMER EE
private void LoadCustomersEE()
{
	List<initialRowCust> Cs = (from c in db.tblCustomersorderby 
                c.FirstName + " " + c.LastNamenew initialRowCust 
                {
		    CustName = c.FirstName + " " + c.LastName,
		    CustomerID = c.CustomerID
	       }).ToList();

	cmbCustomerEE.DataSource = null;
	cmbCustomerEE.DataSource = Cs;
	cmbCustomerEE.DisplayMember = "CustName";
	cmbCustomerEE.ValueMember = "CustomerID";

}

Open in new window


The reason I posted, thinking you maybe wanting to cycle trough records possibly to populate a drop box.  If not, then it possibly could be used to do what you are asking for. Please tell me more about what is that you want to accomplish.

In this example, the combobox is uploaded such that displays the customer FName_LName combination. But, upon click, it gives you customer ID to help with your search.

But, if you want to cycle through names, then replace lines 15 - 18 with:

foreach (void name in Cs)
{
      MessageBox.Show(name.CustName);
}
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 1000 total points
ID: 40541995
Hi  bmanmike39;

I think this should do what you want.

var enumerator = oe.GetEnumerator();

while( enumerator.MoveNext() )
{
    [DataType] currentEntity = enumerator.Current;
    // Where [DataType] is of the type in the collection.
    // Your code here using the current entity from the collection
}

Open in new window

0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40542278
in line 8, need to add single space to change

List<initialRowCust> Cs = (from c in db.tblCustomersorderby

to

List<initialRowCust> Cs = (from c in db.tblCustomers orderby
0
 

Author Closing Comment

by:bmanmike39
ID: 40643025
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question