XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 8th, 2003, 09:31 AM
JCScoobyRS JCScoobyRS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: I'll tell you if you tell me.
Posts: 45 JCScoobyRS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to JCScoobyRS
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

Reply With Quote
  #2  
Old April 8th, 2003, 04:14 PM
Wingman Wingman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Bavaria, Germany
Posts: 140 Wingman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 40 m 41 sec
Reputation Power: 6
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.

Reply With Quote
  #3  
Old April 9th, 2003, 12:32 PM
JCScoobyRS JCScoobyRS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: I'll tell you if you tell me.
Posts: 45 JCScoobyRS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to JCScoobyRS
I found an example online similar to yours. I got it working now. Thanks alot, Jeremy

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML Driven TreeView


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway