title: How to fill treeview and nodes according to parent in C#
body: <p>I have a table in sql: table data goes like:</p>
  
  <pre><code>catid parentid catname
  ----- -------- -------------------
  1     0        Operating Systems
  2     1        Windows
  3     1        Linux
  4     5        Windows Server 2008 
  5     2        Windows Server
  6     1        Unix 
  </code></pre>
  
  <p>Parent id keeps its parent. For example; <em>Windows Server 2008</em> comes first and belongs to <em>Windows Server</em> (its parent sometimes comes later). </p>
  
  <p>In <code>C#</code> side i got that table in dataset, but could not solve rest.</p>
  
  <pre><code>for (int i = 0; i &lt; ds2.Tables[0].Rows.Count; i++)
  {
      TreeNode root = new TreeNode();
      TreeNode child = new TreeNode();
      if (ds.Tables[0].Rows[i]["parentid"] == 0)
      {
  
          root.Text = ds.Tables[0].Rows[i]["catname"];
          trview.Nodes.Add(root);
      }
      else
      {
          child.Text = ds.Tables[0].Rows[i]["catname"];
          root.ChildNodes.Add(child);                       
      }                             
  }
  </code></pre>
  
  <p>How can i fill <code>Treeview</code> according to table. I could not solve how to design loop for it. If <em>parentid</em> is belong to a <em>catid</em>, it will be node of it. </p>
  
  <p>Thank you for any advise or help</p>
  
  <p>Kind Regards</p>