Link to home
Start Free TrialLog in
Avatar of taz8020
taz8020Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Add node under a spacific node, VB.net treeview

Hi I want to be able to add a node, under a spacific node. may be by path or index?

I have a table in a typed dataset in a win app, and need to loop through each row. I have an ID field and a ParentID field. I want it to be able to have infanate child nodes. So the only way I can see of doing this is when adding a node look to see if there are child nodes then add them. |Just not sure how to go about doing this.

This is what I have so far:

For i = 0 To Me.DataSet.sections.Rows.Count - 1
If Me.ActinicDataSet.Catalog_section.Rows(i).Item("ParentID") = 0 Then
Me.TreeView1.Nodes.Add(Me.DataSet.sections.Rows(i).Item("SectionText"))
'Need to add child nodes here.
End If
Next
Avatar of Dennis Aries
Dennis Aries
Flag of Netherlands image

The Add-function returns the created node as a result. You can then use that node as a parent to set the subsequent nodes.
Dim childNode As TreeNode = New TreeNode("Text for new childnode")
TreeNode node = Me.TreeView1.Nodes.Add(Me.DataSet.sections.Rows(i).Item("SectionText"))
node.Add( childNode )
 
Avatar of taz8020

ASKER

Hi djjaries, thanks for that. Is there a way if datasouce has children add child node. and if that childnode has children add thoses nodes and so on.
I have an ID field and a ParentID field in the same data table.

eg
-id
--id
----id
-----id
-id
-----id
ASKER CERTIFIED SOLUTION
Avatar of Dennis Aries
Dennis Aries
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial