Solved

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

Posted on 2015-01-09
4
92 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 250 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 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

615 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