Hi,
I am trying to get used to this .NET thing. I am sure that most of my problems are related to trying to do things the old VB way and not used to the OOP model of .NET.
I have a list box that I am populating from an XML file. I would like to populate it in my Form_Load routine. Reading the XML file is not a problem. I want to read the XML nodes into an arraylist object. Therein lies the problem. I cannot create a reference to system.collections within my Form class, therefore I am forced to do so in a module which I call App_Globals. In this module I can define an object varaible that I wish to use when my form loads. However, I cannot do this because I cannot construct the system.collections.arraylist object becuase the form does not know of it.
Am I missing something?
Code:
///////
Imports System.Collections
Module App_Globals
Public g_arlArrList As ArrayList
End Module
///////
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlDoc As New Xml.XmlDocument
Dim xmlNdList As Xml.XmlNodeList
Dim i As Integer
xmlDoc.Load("../xml/units.xml")
xmlNdList = xmlDoc.GetElementsByTagName("Unit")
For i = 0 To xmlNdList.Count - 1
g_arlArrList.Add(xmlNdList.Item(i))
Next
ListBox1.DataSource = g_arlArrList
End Sub
/////
The code fails because I have not constructed the arraylist object. but if I try to add:
g_arlArrList in the Form_Load subroutine, it does not recognize the ararylist type of object.
I am trying to get used to this .NET thing. I am sure that most of my problems are related to trying to do things the old VB way and not used to the OOP model of .NET.
I have a list box that I am populating from an XML file. I would like to populate it in my Form_Load routine. Reading the XML file is not a problem. I want to read the XML nodes into an arraylist object. Therein lies the problem. I cannot create a reference to system.collections within my Form class, therefore I am forced to do so in a module which I call App_Globals. In this module I can define an object varaible that I wish to use when my form loads. However, I cannot do this because I cannot construct the system.collections.arraylist object becuase the form does not know of it.
Am I missing something?
Code:
///////
Imports System.Collections
Module App_Globals
Public g_arlArrList As ArrayList
End Module
///////
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlDoc As New Xml.XmlDocument
Dim xmlNdList As Xml.XmlNodeList
Dim i As Integer
xmlDoc.Load("../xml/units.xml")
xmlNdList = xmlDoc.GetElementsByTagName("Unit")
For i = 0 To xmlNdList.Count - 1
g_arlArrList.Add(xmlNdList.Item(i))
Next
ListBox1.DataSource = g_arlArrList
End Sub
/////
The code fails because I have not constructed the arraylist object. but if I try to add:
g_arlArrList in the Form_Load subroutine, it does not recognize the ararylist type of object.