List view not updating in vb.net



I am trying to display playlist information from a web service into a list View object using VB.net


I have managed to get the XML from the service and turn it into Strings and created a loop to enter the information into the list view. The problem is that it is always entering the information from the first song several times


enter image description here The result from the web service is shown here


enter image description here


The console log from inside the for loop is:



<name>Test Song one</name><artist>The tested</artist><album>To test</album>
<name>Test two</name><artist>the Tested</artist><album>To test</album>
<name>Test 3</name><artist>Tested</artist><album>To test</album>


Here is the code from this method:



serviceReturn = service.getList(txtPlaylist.Text)
MessageBox.Show(serviceReturn)
Dim doc As New XmlDocument

Dim result As XmlElement = doc.CreateElement("playlist")
result.InnerXml = serviceReturn
Dim lstName As XmlNode = result.SelectSingleNode("/name")

Dim results As XmlNodeList
results = result.GetElementsByTagName("song")
lstSong.Items.Add(lstName.InnerText)
Dim songNod As XmlNode
Dim listName As ListViewItem
For Each songNod In results
listName = New ListViewItem
Console.WriteLine(songNod.InnerXml)
Dim lstSongName As XmlNode = songNod.SelectSingleNode("/song/name")
Dim lstSongArtist As XmlNode = songNod.SelectSingleNode("/song/artist")
Dim lstSongAlbum As XmlNode = songNod.SelectSingleNode("/song/album")

listName = New ListViewItem(lstSongName.InnerText)
listName.SubItems.Add(lstSongArtist.InnerText)
listName.SubItems.Add(lstSongAlbum.InnerText)
detailedView.Items.Add(listName)
listName = Nothing
lstSongName = Nothing
lstSongArtist = Nothing
lstSongAlbum = Nothing

Next


Could anyone point out why it's just printing the first song every time?


Any help would be appreciated.


No comments:

Post a Comment