MultiForm and an ArrayList

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() ) ;
}
 
J

Joe White

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top