Try this. I modify the code posted by Mr. Pawan Kiran.
private void FillTreeView(TreeView Tv, int NoOfLevels, int NoOfChildsOfEachLevel)
{
if (NoOfLevels < 0)
return;
for (int i = 0; i < NoOfChildsOfEachLevel; i++)
{
Tv.Nodes.Add(i.ToString());
FillTreeNode(Tv.Nodes[i], NoOfLevels - 1, NoOfChildsOfEachLevel);
}
}
private void FillTreeNode(TreeNode Tn, int NoOfLevels, int NoOfChildsOfEachLevel)
{
if (NoOfLevels < 0)
return;
for (int i = 0; i < NoOfChildsOfEachLevel; i++)
{
Tn.Nodes.Add(i.ToString());
FillTreeNode(Tn.Nodes[i], NoOfLevels - 1, NoOfChildsOfEachLevel);
}
}