|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
XML Driven TreeView
Does anyone know where to get some good resources on how to build a TreeView, in VB, with data from an XML file? I'd also need my VB Program to be able to modify the XML document during run time. Thanks, Jeremy
__________________
If you can't figure it out yourself, suck it up and ask someone else. DeveloperKB |
|
#2
|
|||
|
|||
|
That's pretty easy since a doc is just a tree and the nodes collection is basicly nothing else but a IXMLDOMNodeList.
Example: Code:
Private Sub Form_Load()
Dim lDoc As DOMDocument
Set lDoc = New DOMDocument40
' load doc
lDoc.Load "C:\test.xml"
' add nodes
AddNodes TreeView1, Nothing, lDoc.DocumentElement
End Sub
Private Sub AddNodes(pTreeView As TreeView, pTreeParent As Node, pDocNode As IXMLDOMElement)
Dim lTreeNode As Node
' add our xml node to our tree (if no parent, then we are
' the root node
If (Not pTreeParent Is Nothing) Then
Set lTreeNode = pTreeView.Nodes.Add(pTreeParent, tvwChild, , pDocNode.baseName)
Else
Set lTreeNode = pTreeView.Nodes.Add(, , , pDocNode.baseName)
End If
' (hint) save our xml node reference in your tag so we can easily
' access our xml node when you just got the TreeView node
Set lTreeNode.Tag = pDocNode
' add all child nodes
Dim lDocChildNode As IXMLDOMElement
For Each lDocChildNode In pDocNode.SelectNodes("*")
AddNodes pTreeView, lTreeNode, lDocChildNode
Next
End Sub
If you dynamicly change your TreeView you must still do all the changes to your xml doc, e.g. if you add a child node to one of your nodes you still need to do a ".appendChild" on your xml node (but that's fairly easy since you always have a "TreeView Node" and with its .Tag property you'll always have access to the correspondending xml node. |
|
#3
|
|||
|
|||
|
I found an example online similar to yours. I got it working now. Thanks alot, Jeremy
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XML Driven TreeView |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|