|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Accessing an arraylist from multiple forms.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 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 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 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 > 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 > > 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 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 > 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 >
incorrect string format
Altering a DBF File Merge/Synchronize XML Files [Regular Expression] (aaa AND bbb) OR (ccc AND ddd) Fundamental OOP inheritance question don't show error windows Unable to remove Beep on Alt+A Can reflection tell the base class of an object? Deleting Values from an XML node? Resource File Woes |
|||||||||||||||||||||||