|
-
Mar 9th, 2006, 01:38 PM
#1
Thread Starter
Member
Populate TreeView component with XML ?
I sow that there is XMLDataSource type for Web developing but how to populate TreeView with XML file?
There is way manualy to do it, probably, but there should be some easier way....
something like>
VB Code:
dim XmlDoc as XMLdocument
XmlDoc.Load("some.xml")
me.treeview1.populate(XmlDoc)
Thanks!!!!
-
Mar 11th, 2006, 03:46 PM
#2
Thread Starter
Member
Re: Populate TreeView component with XML ?
I found solution on Microsoft's web site. Here, for other searchers:
VB Code:
' put this on Button.click procedure, or some else that should start populating
TreeView1.Nodes.Clear()
TreeView1.Nodes.Add(New TreeNode(XmlDoc.DocumentElement.Name))
Dim tNode As New TreeNode()
tNode = TreeView1.Nodes(0)
AddNode(XmlDoc.DocumentElement, tNode)
TreeView1.ExpandAll()
'and also define function that is needed
Private Sub AddNode(ByRef inXmlNode As XmlNode, ByRef inTreeNode As TreeNode)
Dim xNode As XmlNode
Dim tNode As TreeNode
Dim nodeList As XmlNodeList
Dim i As Integer
' Loop through the XML nodes until the leaf is reached.
' Add the nodes to the TreeView during the looping process.
If inXmlNode.HasChildNodes() Then
nodeList = inXmlNode.ChildNodes
For i = 0 To nodeList.Count - 1
xNode = inXmlNode.ChildNodes(i)
inTreeNode.Nodes.Add(New TreeNode(xNode.Name))
tNode = inTreeNode.Nodes(i)
AddNode(xNode, tNode)
Next
Else
' Here you need to pull the data from the XmlNode based on the
' type of node, whether attribute values are required, and so forth.
inTreeNode.Text = (inXmlNode.OuterXml).Trim
End If
End Sub
Original Microsoft's snippet had: Dim i As Long
but IDE showed me some error... so i set it to Integer.
Hope this will help to someone...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|