Home All Groups Group Topic Archive Search About

Accessing an arraylist from multiple forms.

Author
4 Nov 2006 7:13 AM
Paulers
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

Author
4 Nov 2006 9:03 AM
Ravimama
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:
Show quoteHide quote
> 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
Author
4 Nov 2006 5:17 PM
Paulers
I tried this but Form2 does not know what Form1 is. It says it is not
declared.

Ravimama wrote:
Show quoteHide quote
> 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
Author
4 Nov 2006 6:36 PM
Brendon Bezuidenhout
Have you tried creating a new constructor for Form2 to take the ArrayList
ByRef?


Show quoteHide quote
"Paulers" <SuperG***@gmail.com> wrote in message
news:1162660647.377358.55450@h54g2000cwb.googlegroups.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
>
Author
10 Nov 2006 10:58 AM
Ravimama
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:
Show quoteHide quote
> Have you tried creating a new constructor for Form2 to take the ArrayList
> ByRef?
>
>
> "Paulers" <SuperG***@gmail.com> wrote in message
> news:1162660647.377358.55450@h54g2000cwb.googlegroups.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
> >
Author
4 Nov 2006 10:18 AM
Oenone
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
Author
4 Nov 2006 11:42 AM
Theo Verweij
Declare the arraylist in a module.

Paulers wrote:
Show quoteHide quote
> 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
>
Author
4 Nov 2006 2:34 PM
Cor Ligthert [MVP]
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

Show quoteHide quote
"Paulers" <SuperG***@gmail.com> schreef in bericht
news:1162624428.438507.94310@e3g2000cwe.googlegroups.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
>