Load Favorites into TreeView from XML Document not working-VBForums
Results 1 to 3 of 3

Thread: Load Favorites into TreeView from XML Document not working

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    78

    Load Favorites into TreeView from XML Document not working

    Hi, I was making a treeview favorites for my browser and got this code, however, nothing happens on startup, like the treeview stays emty

    Heres the code for the Load handler
    If System.IO.File.Exists(FavFile) Then
    Dim xdoc As New Xml.XmlDocument
    xdoc.Load(FavFile)
    Dim root As Xml.XmlElement = xdoc.Item("Favorites")
    For Each elm As Xml.XmlElement In root
    Select Case elm.Name
    Case "Single"
    Dim tn As New TreeNode
    tn.Name = elm.Attributes("name").Value
    tn.Text = elm.Attributes("name").Value
    tn.Tag = elm.Attributes("url").Value
    FavoritesTreeView.Nodes.Add(tn)
    Case "Group"
    Dim mtn As New TreeNode
    mtn.Name = elm.Attributes("name").Value
    mtn.Text = mtn.Name
    mtn.Tag = "#GROUP#"
    For Each ent As Xml.XmlElement In elm
    Dim tn As New TreeNode
    tn.Name = ent.Attributes("name").Value
    tn.Text = ent.Attributes("name").Value
    tn.Tag = ent.Attributes("url").Value
    mtn.Nodes.Add(tn)
    Next
    FavoritesTreeView.Nodes.Add(mtn)
    End Select
    Next

    End If

    and heres the xml document (at the top i have : Private FavFile As String = Application.StartupPath & "\favs.xml")

    <?xml version="1.0" encoding="utf-8" ?>
    <Favorites>
    <Single name="MSN.com" url="http://www.msn.com" />
    <Group name="C/N">
    <Entry name="[adult swim]" url="http://www.adultswim.com" />
    <Entry name="Cartoon Network" url="http://www.cartoonnetwork.com" />
    </Group>
    </Favorites>

    nothing loads into the treeview though

    does anyone know why? the exact same code works for the orginal project, and I have the same xml document in the same subfolders for my project

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Load Favorites into TreeView from XML Document not working

    Have you tried stepping through the code to see what happens? Does code ever reach one of the lines which adds a node to the treeview?

    Its hard to read your code because you haven't used the CODE tags which would preserve indentation etc. but it looks to me like you've got

    "FavoritesTreeView.Nodes.Add(mtn)"

    outside of the cases where it should be applied.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2009
    Posts
    78

    Re: Load Favorites into TreeView from XML Document not working

    Wow quick reply

    I'll try using the message box thing

    sorry about code thing

    I'm on iPone now just left home

    the mtn thing I think works cuz that's for groups and groups work

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.