I have a problem that I cannot seem to solve.
I am building a TreeView dynamically and I have an ordered list. I want the TreeView to build in such a way:
Node1
_Node2
__ Node3
__ _Node..N
My code is as follows:
TreeNode tn = new TreeNode(); for (int i = 0; i < EmployeesReportingLine.Count; i++ ) { Employee ep = EmployeesReportingLine[i]; while (tn.ChildNodes.Count > 0) tn = tn.ChildNodes[0]; TreeNode temp = new TreeNode(ep.FullName); if (i > 0) tn.ChildNodes.Add(temp); else tn = temp; } TreeView1.Nodes.Add(tn);
I have made several other attempts at using recursive functions but the snippet above was my best attempt.
Thanks in advance.
Or: