Results 1 to 4 of 4

Thread: [RESOLVED] XML Function does not add items to ListView. Why?

  1. #1

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Resolved [RESOLVED] XML Function does not add items to ListView. Why?

    I call the following code:
    VB.Net Code:
    1. Public Sub LoadXML(ByVal file As String, ByVal ListViewName As ListView)
    2.  
    3.         Dim XMLfile As New XmlTextReader(file)
    4.         XMLfile.WhitespaceHandling = WhitespaceHandling.None
    5.         XMLfile.Read()
    6.         XMLfile.Read()
    7.  
    8.         While Not XMLfile.EOF
    9.             If Not XMLfile.IsStartElement() Then 'Check it's actually a tag and not crap.
    10.                 Exit While
    11.             End If
    12.             Dim X As New ListViewItem
    13.             Dim FileName = XMLfile.GetAttribute("fn")
    14.             XMLfile.Read()
    15.             Dim artist = XMLfile.ReadElementString("artist")
    16.             Dim title = XMLfile.ReadElementString("title")
    17.             Dim album = XMLfile.ReadElementString("album")
    18.  
    19.             X = ListViewName.Items.Add(FileName)
    20.             X.SubItems.Add(artist)
    21.             X.SubItems.Add(title)
    22.             X.SubItems.Add(album)
    23.         End While
    24.         XMLfile.Close()
    25.  
    26.     End Sub

    Using the following call:
    VB.Net Code:
    1. LoadXML("C:\Users\Dev\Documents\Sample.XML", Form2.ListView2)

    However, no errors are shown, the items are not added to the ListView.
    Also, if i check the values of "artist", it is populated, as are the rest.
    It just, for some reason, does not add to a listview on another form.
    Zeegnahtuer?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: XML Function does not add items to ListView. Why?

    vb Code:
    1. Dim X As New ListViewItem(FileName)
    2. X.SubItems.Add(artist)            
    3. X.SubItems.Add(title)            
    4. X.SubItems.Add(album)
    5. ListViewName.Items.Add(X)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: XML Function does not add items to ListView. Why?

    also your variables aren't declared properly:

    vb Code:
    1. Dim FileName = XMLfile.GetAttribute("fn")

    should be:

    vb Code:
    1. Dim FileName as string = XMLfile.GetAttribute("fn")

  4. #4

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: XML Function does not add items to ListView. Why?

    Got it, i realised i was calling the wrong form, i should have used:

    LoadXML("C:\Users\Dev\Documents\Sample.XML", FormSingleton(Of Form2).Form.ListView2)

    As i created the form using a custom class written by someone here on these boards.


    EDIT: (To the post above) And yep, i noticed that reading my code back, it is fixed now
    Zeegnahtuer?

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