I have a list like this
-
ID | Name | Title | ManagerID
-
1 | Peter | CEO | Null
- 2 | Eric | Manager | 1
- 3 | brad | Economy | 1
- 4 | Pit | Sales | 2
- 5 | Mike | Secretary| 4
- 6 | Mac | copier | 5
- 7 | Ben | Board | Null
This list can be infinite. The null values in this are because they have no Manager.
How can I add this to a treeview and get all the parentnode and subnodes correctly?
Need to accomplish this in a loop, and cannot change the database where it comes from,
I want to do something like?
private void treew(TreeNode treeNode, List<Employees> employ)
{
foreach (Employees option in employ)
{
TreeNode nodeOutput;
//Add parent node
foreach (Employees optionItems in employ)
{
if (option.ID == optionItems.ManagerID)
{
//Add childnode
TreeNode nodeOption;
nodeOutput.Nodes.Add(nodeOption);
}
}
treeNode.Nodes.Add(nodeOutput);
}
}
Either pass in the root node of your TreeView to the first call, or create another version which takes the TreeView as the first argument and does pretty much the same thing.