I have figured out how to populate a treeview with an xml file however
I just can't for the life of me get this formatting of the nodes
right.
Here's where I'm at:
<Season>
<Fruit>Orange</Fruit>
<Fruit>Strawberry</Fruit>
<Fruit>Banana</Fruit>
</Season>
Produces: (no pun intended)
--Season
+---Fruit
|__Orange
+---Fruit
|__Strawberry
+---Fruit
|__Banana
Is there a way that I can just have:
-Orange
-Strawberry
-Banana
Bonus Question:
Is there a click event associated with this? (New to XML and the
Treeview Control)
For example if the XML file looked like this:
<Season>
<Fruit>
<Type>Orange</Type>
<Taste>Good</Taste>
</Fruit>
<Fruit>
<Type>Strawberry</Type>
<Taste>Great</Taste>
</Fruit>
<Fruit>
<Type>Banana</Type>
<Taste>Amazing</Taste>
</Fruit>
</Season>
Could I populate textboxes with the information for "Taste". If the
user clicks on
-Orange
Then txtTaste would fill in with "Good"
is this possible?
TIA,
Lewis
BTW This is what I am currently using to fill the Treeview. I got
this off of various posts throughout the MS forum.
'Load the TreeView
' SECTION 1. Create a DOM Document and load the XML
data into it.
Dim dom As New XmlDocument()
dom.Load(Path)
' SECTION 2. Initialize the treeview control.
tvFruitMenu.Nodes.Clear()
tvFruitMenu.Nodes.Add(New
TreeNode(dom.DocumentElement.Name))
Dim tNode As New TreeNode()
' SECTION 3. Populate the TreeView with the DOM nodes.
AddNode(dom.DocumentElement, tNode)
' SECTION 4. Create a new TreeView Node with only the
child nodes.
Dim nodelist As XmlNodeList = dom.SelectNodes("//
Name")
Dim cDom As New XmlDocument()
cDom.LoadXml("<Name></Name>")
Dim node As XmlNode
For Each node In nodelist
Dim newElem As XmlNode =
cDom.CreateNode(XmlNodeType.Element, node.Name, node.LocalName)
newElem.InnerText = node.InnerText
cDom.DocumentElement.AppendChild(newElem)
Next
tvFruitMenu.Nodes.Add(New
TreeNode(cDom.DocumentElement.Name))
tNode = tvFruitMenu.Nodes(1)
AddNode(cDom.DocumentElement, tNode)
tvFruitMenu.ExpandAll()