MultiForm and an ArrayList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi ,
In C#
I have a problem when I need to get the ArrayList Data in
another form
My ArrayList is empty .
I write this code to show you the problem
Please help

Form1 :

Public ArrayList Arr = new ArrayList() ;

for (int i = 0 ; i < 20 ; i ++ )
{
Arr.Add(i) ;
}

Form2 :

Form1 Fm1 = new Form1() ;
for (int i = 0 ; i <
Fm1.Arr.Count -1 ; i ++ )
{
MessageBox.Show( Fm1.Arr
.ToString() ) ;
}
 
1. I hope this is just demo code, and that your *real* programs don't
have public fields, or use "for" when you should be using "foreach", or
have off-by-one errors that miss the last element in the list. <grin>

2. You give the Form1 code that populates the ArrayList, but you don't
specify which method this code is in. I'm guessing that it's in your
Form1_Load method, right? Because I just ran a quick test, and found
(much to my surprise) that the form's Load event doesn't fire unless you
actually show the form. Try initializing the ArrayList in the form's
constructor instead, and see if that helps.
 
Back
Top