Skip to content

Processing XML into TreeView

Xistins

Asked May 10, 2007, 12:44 AM EDT2 answers
Share
LinkedInX
Hi all. I am relativity new to VB 2005. I am currently working on my first real project which is a "personal knowledge base." Essentially it will have the ability to store multiple articles in several categories and sub-categories. The articles will be stored in a rtf file, but the general information will be stored in and XML file that will be used to populate a tree view on the application it self. Just for a visual the XML will look something like My problem comes from pulling the information from this file and populating the tree view. I have 2 test categories with several subcategories each. I'm using one class for all the populating. It looks something like this. Public Sub treePopulator() config.Load(xr) Dim cats As System.Xml.XmlNodeList = config.SelectNodes("tvMain/category") Dim subs As System.Xml.XmlNodeList = config.SelectNodes("tvMain/category/subcategory") Dim a, b Dim name As String Dim parent As Integer For a = 1 To cats.Count name = cats.Item(a - 1).Attributes("name").Value.ToString frmMain.tvMain.Nodes.Add(name.ToString) For b = 1 To subs.Count parent = subs.Item(b - 1).ParentNode.Attributes("cid").Value name = subs.Item(b - 1).Attributes("name").Value frmMain.tvMain.Nodes(parent).Nodes.Add(name) Next b Next a End Sub When I run this code it processes the first category but doubles all the child nodes. In the second it errors on the line that adds the parent node with the following... "Specified argument was out of the range of valid values. parameter name: index" Any help anyone can provide on this would be great. I thank you in advance. Xistins

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    OKAY that ripped out all the formating. If someone can help I will email the code I have to them for them to look at.
    0
  • 0
    Nevermind. :) I figured it out.
    0