jmDesktop wrote:
I have this:
foreach (DataRow row in myDS.Tables["myTable"].Rows)
{
int ctr=0; //counter for child node
//create a parent node for each new row
trvRetrieved.Nodes.Add(new
TreeNode(myIdNumber));
//children of that parent row
trvRetrieved.Nodes[ctr].Nodes.Add(new
TreeNode(myPerson));
trvRetrieved.Nodes[ctr].Nodes.Add(new
TreeNode(myAddress));
ctr++;
}
Is there a way to get the current row iteration number I am on instead
of using the by hand int counter?
Thank you.
No, the enumerator doesn't expose the index of the current item.
You can rewrite the loop to use an index instead of an enumerator:
DataRowCollection rows = myDS.Tables["myTable"].Rows;
for (int ctr = 0; ctr < rows.Count; ctr++) {
DataRow row = rows[ctr];
//create a parent node for each new row
trvRetrieved.Nodes.Add(new TreeNode(myIdNumber));
//children of that parent row
trvRetrieved.Nodes[ctr].Nodes.Add(new TreeNode(myPerson));
trvRetrieved.Nodes[ctr].Nodes.Add(new TreeNode(myAddress));
}
--
Göran Andersson
_____
http://www.guffa.com