child nodes of treeview node

Zelgadis

New Member
I have an xml file with following structure:\[code\]<table name="tblcats"> <row> <Id>3680</Id> <Industry>Associations</Industry> <ParentId>1810</ParentId> </row> <row> <Id>1592</Id> <Industry>Fortune 100</Industry> <ParentId>1810</ParentId> </row> <row> <Id>1601</Id> <Industry>Oil & Gas Operations</Industry> <ParentId>1689</ParentId> </row> <row></table>\[/code\]I want to create a treeview using this XML file. I have written following code\[code\] ' Load a TreeView control from an XML file. Private Sub LoadTreeViewFromXmlFile(ByVal file_name As String, ByVal trv As TreeView) ' Load the XML document. Dim xml_doc As New XmlDocument xml_doc.Load(file_name) ' Add the root node's children to the TreeView. trv.Nodes.Clear() trv.Nodes.Add(New TreeNode(xml_doc.DocumentElement.Name)) AddTreeViewChildNodes(trv.Nodes, xml_doc.DocumentElement) End Sub ' Add the children of this XML node ' to this child nodes collection. Private Sub AddTreeViewChildNodes(ByVal parent_nodes As TreeNodeCollection, ByVal xml_node As XmlNode) For Each child_node As XmlNode In xml_node.ChildNodes ' Make the new TreeView node. Dim new_node As TreeNode = New TreeNode(child_node.Item("Industry").InnerText, child_node.Item("Id").InnerText) parent_nodes.Add(new_node) Next child_node End Sub\[/code\]but it creates a treeview like this:\[code\]->table->Associations->Fortune 100\[/code\]where as I want table as parent element like this\[code\]->table ->Associations ->Fortune 100\[/code\]so that If i click table node, all tree collapses or expands. Please suggest how can i fix it
 
Back
Top