title: How can I add child nodes to a treeview with deciding the depth level?
body: <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace Treeview_Test
  {
      public partial class Form1 : Form
      { 
          int numberofroots = 1000;
          int childsnum = 50;
          int leveldepth = 0;
  
          public Form1()
          {
              InitializeComponent();
  
              AddNodes();
          }
  
          private void AddNodes()
          {
              advancedTreeView1.Nodes.Clear();
  
              for (int i = 0; i &lt; numberofroots; i++)
              {
                  advancedTreeView1.Nodes.Add("New Node " + i.ToString());
  
                  TreeNode subnode = advancedTreeView1.Nodes[i];
  
                  if(allRootsWithChilds.Checked)
                  {
                      subnode.Nodes.Add("New Node " + i.ToString());
                  }
                  else
                  {
                      if (i &lt; childsnum)
                      {
                          subnode.Nodes.Add("New Node " + i.ToString());
                      }
                  }
              }
          }
  
          private void allRootsWithChilds_CheckedChanged(object sender, EventArgs e)
          {
                  AddNodes();
          }
      }
  }
  </code></pre>
  
  <p>Now if the checkbox is checked it will add one child to all the root nodes. All the 1000 root nodes will have one child. If unchecked only the first 50 root nodes out of the 1000 will have one child.</p>
  
  <p>What I want to do now is if the checkbox is checked or not the root nodes that have once child I want to decide the depth level. For example if the depth level is 1 then the first 50 root nodes or all the root nodes will have one child.</p>
  
  <p>But if the depth level is for example 4 then each of the root nodes if it's 50 or all of them will have 4 childs :</p>
  
  <pre><code>Node0
    Node1
      Node2
        Node3
          Node4
  Node1
    Node1
      Node2
        Node3
          Node4
  ....
  Node49
    Node1
      Node2
        Node3
          Node4
  </code></pre>
  
  <p>The variable childsnum decide how many root nodes will have childs.
  The variable leveldepth should decide how deep to add childs to each root node.
  And then I want to add another int variable to decide on each level how many childs to have.</p>
  
  <p>For example in level 3 there will be 50 nodes for each root node.
  And at level 1 there will be only 1 node for each root nodes.</p>