Xistins

Xistins

  • NA
  • 5
  • 0

Processing XML into TreeView

May 10 2007 4:44 AM
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

Answers (2)