Thursday, 5 September 2013

How to add sub child nodes to a child node in Treeview dynamically in C#?

How to add sub child nodes to a child node in Treeview dynamically in C#?

Am trying to add the tree view based on the list. Am getting an out of
range exception.
for (int i = MyList.Count; i > 0 ; i--)
{
MyTree.Nodes.Add(MyList[i].GetP() + " " + MyList[i].GetSt());
MyTree.Nodes[i].Nodes.Add(MyList[i].GetSe());
MyTree.Nodes[i].Nodes[i].Nodes.Add(MyList[i].GetI());
}
Am able to populate the treeview with hardcoded values. i.e.,
MyTree.Nodes[0].Nodes[0].Nodes.Add(MyList[0].GetI());
Kindly help me to resolve this exception.

No comments:

Post a Comment