I have written a nested-loop for adding Tree-Nodes, problem is that index i never increments to 1.
In For Each Loop: where there are no more child nodes in first Parent Node, the loop stops in index j and does not go back to index i to increment to 1.
for (int i = 0; i < 23; i++)
{
for (int j = 0; j < 23; j++)
{
foreach (var item in myDictionaryReconstructed)
{
if ("TreeNode: " + item.Key == treeView1.Nodes[i].Nodes[j].ToString())
{
treeView1.Nodes[i].Nodes[j].Nodes.Add(item.Value);
treeView1.ExpandAll();
}
}
}
}
For Example:
Parent Node 1 - Sub-Node 1 - Sub-Node 2 - Sub-Node 3
Parent Node 2 - Sub-Node 1 -
Parent Node 3 - Sub-Node 1
The Program executes upto Parent Node - 1 and Sub-Node 3. When the sub-node is 4 being checked and it's not found, the program just stops there, instead of moving to next parent node.
Exception: Specified Argument was out of range of valid values Parameter name index.
Answer to duplicate: after discussing later I found the exception above, my question was posted earlier before I didn't know that it's an index exception.