I am trying to add get items from an xml document and load it into a listview. I keep getting an System.OutOfMemory exception on the line projects.Add(project). What am I doing wrong and how do I do it correctly? I got this code from murach's beginning visual basic.NET. When I run this it adds random spaces between the items in the listview
Structure ProjectInfo
Dim name As String
Dim fileextentions As ArrayList
Dim imagepath As String
End Structure
Dim project As ProjectInfo
Dim projects As New ArrayList()
'The project is loading
Private Sub diaNewProject_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Set the default filepath
txtFilepath.Text = "C:\Users\" & GetUserName() & "\Documents\Homerun IDE\Projects"
'Load the project types
If LoadProjects() Then
For Each Me.project In projects
'Add the items
ltvItems.Items.Add(project.name)
Next
Else
'Close the form
Me.Close()
End If
End Sub
Private Function LoadProjects() As Boolean
Dim ProjectReader As New XmlTextReader(_globals.ProjectsListFilename)
ProjectReader.WhitespaceHandling = WhitespaceHandling.None
Try
Do Until ProjectReader.Name = "projecttype"
ProjectReader.Read()
Loop
Do While ProjectReader.Read()
If ProjectReader.Name = "projecttype" Then
project.name = ProjectReader.Item(Name)
projects.Add(project)
End If
Loop
ProjectReader.Close()
Catch ex As XmlException
_logger.LogException(ex, TraceEventType.Critical, "Load Projects Error", "Make sure that your projectstypes.xml file is correctly formatted. In your settings " & _
"you can reset the file to your its default.")
Return False
End Try
Return True
End Function