title: Converting TreeNode to DataTable Dynamically
body: <p>There are plenty of methods to convert datatable into treeview (treenode) like <a href="https://stackoverflow.com/questions/805457/populate-winfrom-treeview-from-datatable">this</a>. But is there any way to do create a datatable maintaining hierarchy. For ex. if <code>TreeNode</code> is like</p>
  
  <pre><code>A-A1
   -A2-A21
      -A22
  B-B1
   -B2-B21
   -B3-B31
      -B32-B321
          -B322
      -B33
   -B4
  </code></pre>
  
  <p>should look like following in datatable. Then i can either save it in the databse or show it to the user in a <code>datagrid</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/7lQrz.png" alt="enter image description here"></p>
  
  <p>All column  can have take <code>string</code> values.</p>
  
  <p>Is there any way so i can pass a <code>treenode</code> to a function &amp; it will create datatble like this dynamically. <code>treenode</code> structure will change everytime that's why i can not hardcode it. Suppose i have a recursive function like this.</p>
  
  <pre><code>public void CreateData(TreeNode trn)
  {
  
     foreach(TreeNode t in trn.Nodes)
     {
         CreateData(t);
     }
  
  }
  </code></pre>
  
  <p>i am facing difficulty in understanding flow of code for recursive function.
  any suggestion is appreciated.</p>
  
  <p>Thanks.</p>