By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,088 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Accessing an arraylist from multiple forms.

P: n/a
Hello all,

I have 2 forms, form1 and form2. I am trying to store some objects in
an arraylist and have the arraylist be accessible by both forms. How
would I go about doing that? I think I might have to pass the arraylist
object to the second form so that it can access the objects inside the
arraylist but I am not sure what that looks like. any help is greatly
appreciated.

thanks

Nov 4 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hello Paulers,

Suppose you have alName as the array list in form1 which you want to
pass to form 2:
1. Declare the array list as Shared in form 1.
2. Access the arraylist of form 1 in form2 using: form1.alName
Paulers wrote:
Hello all,

I have 2 forms, form1 and form2. I am trying to store some objects in
an arraylist and have the arraylist be accessible by both forms. How
would I go about doing that? I think I might have to pass the arraylist
object to the second form so that it can access the objects inside the
arraylist but I am not sure what that looks like. any help is greatly
appreciated.

thanks
Nov 4 '06 #2

P: n/a
Paulers wrote:

In your second form, add the following to the declarations:

\\\
Public myArrayList As ArrayList
///

When opening your second form from within your first form, set the field you
have declared as follows:

\\\
Dim myForm2 As New Form2

myForm2.myArrayList = arrayListFromForm1

myForm2.ShowDialog()
///

Now from within Form2 you can access the ArrayList however you wish using
the myArrayList object reference. Be aware that it is the actual same
ArrayList object as used by Form1, not a copy, so any changes you make to
its items will be seen by Form1 too.

Hope that helps,

--

(O)enone
Nov 4 '06 #3

P: n/a
Declare the arraylist in a module.

Paulers wrote:
Hello all,

I have 2 forms, form1 and form2. I am trying to store some objects in
an arraylist and have the arraylist be accessible by both forms. How
would I go about doing that? I think I might have to pass the arraylist
object to the second form so that it can access the objects inside the
arraylist but I am not sure what that looks like. any help is greatly
appreciated.

thanks
Nov 4 '06 #4

P: n/a
Paulers,

In my idea does this completely depends on your design.

The first two answers have to do with a situation where there is a main form
and a kind of dialog form.

The answer from Theo is based that your arraylist has to be persistent in
your program undepended if there are active forms.

Cor

"Paulers" <Su*******@gmail.comschreef in bericht
news:11*********************@e3g2000cwe.googlegrou ps.com...
Hello all,

I have 2 forms, form1 and form2. I am trying to store some objects in
an arraylist and have the arraylist be accessible by both forms. How
would I go about doing that? I think I might have to pass the arraylist
object to the second form so that it can access the objects inside the
arraylist but I am not sure what that looks like. any help is greatly
appreciated.

thanks

Nov 4 '06 #5

P: n/a
I tried this but Form2 does not know what Form1 is. It says it is not
declared.

Ravimama wrote:
Hello Paulers,

Suppose you have alName as the array list in form1 which you want to
pass to form 2:
1. Declare the array list as Shared in form 1.
2. Access the arraylist of form 1 in form2 using: form1.alName
Paulers wrote:
Hello all,

I have 2 forms, form1 and form2. I am trying to store some objects in
an arraylist and have the arraylist be accessible by both forms. How
would I go about doing that? I think I might have to pass the arraylist
object to the second form so that it can access the objects inside the
arraylist but I am not sure what that looks like. any help is greatly
appreciated.

thanks
Nov 4 '06 #6

P: n/a
Have you tried creating a new constructor for Form2 to take the ArrayList
ByRef?
"Paulers" <Su*******@gmail.comwrote in message
news:11*********************@h54g2000cwb.googlegro ups.com...
>I tried this but Form2 does not know what Form1 is. It says it is not
declared.

Ravimama wrote:
>Hello Paulers,

Suppose you have alName as the array list in form1 which you want to
pass to form 2:
1. Declare the array list as Shared in form 1.
2. Access the arraylist of form 1 in form2 using: form1.alName
Paulers wrote:
Hello all,

I have 2 forms, form1 and form2. I am trying to store some objects in
an arraylist and have the arraylist be accessible by both forms. How
would I go about doing that? I think I might have to pass the arraylist
object to the second form so that it can access the objects inside the
arraylist but I am not sure what that looks like. any help is greatly
appreciated.

thanks
Nov 4 '06 #7

P: n/a
Hey Paulers,

Did you try the solution I had given. As per the situation you have
given it should work. Its very simple.
Ravi
Brendon Bezuidenhout wrote:
Have you tried creating a new constructor for Form2 to take the ArrayList
ByRef?
"Paulers" <Su*******@gmail.comwrote in message
news:11*********************@h54g2000cwb.googlegro ups.com...
I tried this but Form2 does not know what Form1 is. It says it is not
declared.

Ravimama wrote:
Hello Paulers,

Suppose you have alName as the array list in form1 which you want to
pass to form 2:
1. Declare the array list as Shared in form 1.
2. Access the arraylist of form 1 in form2 using: form1.alName
Paulers wrote:
Hello all,

I have 2 forms, form1 and form2. I am trying to store some objects in
an arraylist and have the arraylist be accessible by both forms. How
would I go about doing that? I think I might have to pass the arraylist
object to the second form so that it can access the objects inside the
arraylist but I am not sure what that looks like. any help is greatly
appreciated.

thanks
Nov 10 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.