Adding Nodes to TreeView and XML files 
Author Message
 Adding Nodes to TreeView and XML files

Can any one give me an example of adding Nodes to a treeview and adding
child nodes?

Also, how would I get the parent node for an app.config file?

For example:

<appsettings>
    <add key="Name" value="Seth" />
        <UselessInfo>
                <add key="Blah" value="Blahblah" />
        </UselessInfo>
</appsetting

I want to be able to see that the parent node for key 'Blah' is
<UselessInfo>, and <UselessInfo>'s parent is <appsettings>.

Thanks,

Seth



Sat, 09 Jul 2005 12:21:11 GMT  
 Adding Nodes to TreeView and XML files
All you should have to do is write a recursive loop to do it, passing in the
first node in your xml document and the current node to add the child to in
the treeview...pseudo code follows:

Private Sub AttachNode(ByVal XMLNode As XmlElement, ByVal ParentNode As
TreeNode)
    Dim TempNode As TreeNode =
ParentNode.Nodes.Add(XMLNode.Attributes.Item(0).NodeValue)
    Dim i As Byte
    For i = 0 To XMLNode.ChildNodes.Length - 1
        AttachNode(XMLNode.ChildNodes.Item(i), TempNode)
    Next
End Sub

Just call it after your XML is loaded and pass it the first node in the
document and the first node in the treeview to start it off

Hope this helps

Erik Porter
Microsoft .NET MVP


Quote:
> Can any one give me an example of adding Nodes to a treeview and adding
> child nodes?

> Also, how would I get the parent node for an app.config file?

> For example:

> <appsettings>
>     <add key="Name" value="Seth" />
>         <UselessInfo>
>                 <add key="Blah" value="Blahblah" />
>         </UselessInfo>
> </appsetting

> I want to be able to see that the parent node for key 'Blah' is
> <UselessInfo>, and <UselessInfo>'s parent is <appsettings>.

> Thanks,

> Seth



Sat, 09 Jul 2005 14:37:05 GMT  
 Adding Nodes to TreeView and XML files

Quote:
>All you should have to do is write a recursive loop to do it, passing in the
>first node in your xml document and the current node to add the child to in
>the treeview...pseudo code follows:

>Private Sub AttachNode(ByVal XMLNode As XmlElement, ByVal ParentNode As
>TreeNode)

>Just call it after your XML is loaded and pass it the first node in the
>document and the first node in the treeview to start it off

Will your code work for a standard (ie: Non-XML)???

Bruce



Mon, 11 Jul 2005 14:49:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. treeview node count not incrementing when adding new nodes

2. Loading XML Nodes in a treeview control

3. hyperlinking a node in one xml file to a node in another xml file??? Best way??

4. XML copy subnodes from one node to another node in another doc

5. XML copy subnodes from one node to another node in another doc

6. Trying to append a simple XML document as a node in an XML document

7. XML: Using XPath navigation to enumerate certain xml nodes

8. Adding nodes to Treeview

9. Adding a node to a treeview from a different thread

10. Adding TreeView nodes in separate thread

11. adding a node to treeview from another thread

12. Recursive TreeView (adding extra nodes)

 

 
Powered by phpBB® Forum Software