title: ASP.net Treeview with child node on childnode
body: <p>I have been given a dataset to work with that is layed out in the format of </p>
  
  <pre><code>Object | Type | Level | Comments | Parent | Child
  </code></pre>
  
  <p>So far I have been able to get the Object as the Parent Node and the Comments as a child node, however I need to get multiple children for this parent, and then children on them</p>
  
  <p>An example of what I mean is like so </p>
  
  <pre><code>Object | Type | Level | Comments | Parent | Child
  Dave   | WH   | 1     | comment  | root   | null
  Simon  | WH   | 1     | comment  | root   | Fortnum
  Simon  | WH   | 1     | comment  | root   | Mason
  Tim    | WH   | 1     | comment  | root   | null
  wallace| WH   | 2     | comment  | Simon  | null
  Mason  | WH   | 2     | comment  | Simon  | Mouse
  Mouse  | WH   | 3     | comment  | Mason  | null
  </code></pre>
  
  <p>I need it to look like this </p>
  
  <p><a href="https://i.stack.imgur.com/IMcdH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IMcdH.png" alt="enter image description here"></a></p>
  
  <p>I have looked at the code from here <a href="https://stackoverflow.com/questions/9963870/vb-net-how-to-add-a-child-node-to-a-specific-node-in-treeview">Similar Stack Answer</a> but its not working for me</p>
  
  <p>I am pulling the sql data into a datatable and then looping through it to try and build the tree view. </p>
  
  <p>This is the code that I am using that is only giving me the object as a parent node, and then the comment as a child node, but I need to be able to locate the actual children of the and then add them to the treeview. </p>
  
  <pre><code>        For Each row As DataRow In dt.Rows
          node = Searchnode(row.Item(4).ToString(), TreeView1)
          If node IsNot Nothing Then
              subNode = New TreeNode(row.Item(3).ToString())
              node.ChildNodes.Add(subNode)
          Else
              node = New TreeNode(row.Item(0).ToString())
              subNode = New TreeNode(row.Item(3).ToString())
              node.ChildNodes.Add(subNode)
              TreeView1.Nodes.Add(node)
          End If
       Next
  </code></pre>
  
  <p>then the function </p>
  
  <pre><code>Private Function Searchnode(ByVal nodetext As String, ByVal trv As TreeView) As TreeNode
      For Each node As TreeNode In trv.Nodes
          If node.Text = nodetext Then
              Return node
          End If
      Next
  End Function
  </code></pre>
  
  <p>Ive never really worked with treeviews before in ASP.Net but would be very grateful if anyone can help me. </p>