|
-
May 31st, 2009, 11:08 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] XML Function does not add items to ListView. Why?
I call the following code:
VB.Net Code:
Public Sub LoadXML(ByVal file As String, ByVal ListViewName As ListView)
Dim XMLfile As New XmlTextReader(file)
XMLfile.WhitespaceHandling = WhitespaceHandling.None
XMLfile.Read()
XMLfile.Read()
While Not XMLfile.EOF
If Not XMLfile.IsStartElement() Then 'Check it's actually a tag and not crap.
Exit While
End If
Dim X As New ListViewItem
Dim FileName = XMLfile.GetAttribute("fn")
XMLfile.Read()
Dim artist = XMLfile.ReadElementString("artist")
Dim title = XMLfile.ReadElementString("title")
Dim album = XMLfile.ReadElementString("album")
X = ListViewName.Items.Add(FileName)
X.SubItems.Add(artist)
X.SubItems.Add(title)
X.SubItems.Add(album)
End While
XMLfile.Close()
End Sub
Using the following call:
VB.Net Code:
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.
-
May 31st, 2009, 11:31 AM
#2
Re: XML Function does not add items to ListView. Why?
vb Code:
Dim X As New ListViewItem(FileName)
X.SubItems.Add(artist)
X.SubItems.Add(title)
X.SubItems.Add(album)
ListViewName.Items.Add(X)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 31st, 2009, 11:39 AM
#3
Re: XML Function does not add items to ListView. Why?
also your variables aren't declared properly:
vb Code:
Dim FileName = XMLfile.GetAttribute("fn")
should be:
vb Code:
Dim FileName as string = XMLfile.GetAttribute("fn")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 31st, 2009, 11:46 AM
#4
Thread Starter
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|