Results 1 to 5 of 5

Thread: [RESOLVED] ListView/XML Problem

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    17

    Resolved [RESOLVED] ListView/XML Problem

    Hello other friendly developers!
    I've got a little frustrating problem, because I can't find the problem in my code:

    1: I've got a form containing one control (ListView1, a ListView control)

    2: I've got this XML File (WebSites.xml)
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <WebSites>
      <WebSite>
        <Name>ASP.NET</Name>
        <URL>http://www.asp.net</URL>
        <Info>Hierzo Info</Info>
      </WebSite>
      <WebSite>
        <Name>Windows Forms</Name>
        <URL>http://www.windowsforms.net</URL>
        <Info>All about Windows Forms</Info>
      </WebSite>
      <WebSite>
        <Name>GotDotNet</Name>
        <URL>http://www.gotdotnet.com</URL>
        <Info>GotDotNet Programme</Info>
      </WebSite>
    </WebSites>
    3: I've got this VisualBasic.NET2 code:
    Code:
    Dim rdrXML As New Xml.XmlTextReader("WebSites.xml")
            rdrXML.MoveToContent()
    
            Dim ElementName As String = ""
            Dim objListViewItem As ListViewItem = Nothing
    
            Do While rdrXML.Read
                objListViewItem = New ListViewItem
    
                ListView1.Items.Add(objListViewItem)
                If rdrXML.NodeType = 1 Then
                    ElementName = rdrXML.Name
                ElseIf rdrXML.NodeType = 3 Then
                    If ElementName = "Name" Then
                        objListViewItem.Text = rdrXML.Value
                    End If
                    If ElementName = "URL" Then
                        objListViewItem.SubItems.Add(rdrXML.Value.ToString)
                    End If
                    If ElementName = "Info" Then
                        objListViewItem.SubItems.Add(rdrXML.Value.ToString)
                    End If
                End If
            Loop
            rdrXML.Close()
    However, I get this strange result. I want all the properties in one row (For each website a row containing Name, URL and Info).

    Can anyone help me? This really makes my head feel like exploding!
    Attached Images Attached Images  
    Last edited by DumbAndDumber; Dec 5th, 2009 at 03:19 PM. Reason: Removed a confusing line of code unneeded

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
  •  



Click Here to Expand Forum to Full Width