sharing objects controls between forms???

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

Guest

frmMISRoutine is the 3rd form in myApp.
the following code is in the 2nd form of myApp.
I don't get any errors but it never builds the array list.
Can you access another foprms control in this way.
I have accessed variables thru setReceive etc but have not tried to access
an actual control.

Dim LogtoSet1 As New ArrayList
Dim frmMISRoutine As New Routines

For Each Item As Object In frmMISRoutine.ChkListBoxRoutines.Items
LogtoSet1.Add(Item)
Next

For Each Item As Object In LogtoSet1
....do stuff
 
marcmc said:
frmMISRoutine is the 3rd form in myApp.
the following code is in the 2nd form of myApp.
I don't get any errors but it never builds the array list.
Can you access another foprms control in this way.
I have accessed variables thru setReceive etc but have not tried to access
an actual control.

Dim LogtoSet1 As New ArrayList
Dim frmMISRoutine As New Routines

For Each Item As Object In frmMISRoutine.ChkListBoxRoutines.Items
LogtoSet1.Add(Item)
Next

For Each Item As Object In LogtoSet1
...do stuff

Yes you can access items like this from another form, although I think
OO guys would look down on it a little.

I assume you have make ChkListBoxRoutines a public control. If that's
the case then the reason that the array is never built is because
ChkListBoxRoutines.items is empty. do:

Debug.Writeline(frmMISRoutine.ChkListBoxRoutines.Count)

to check it. My guess would be that you are adding items to that
collection in the Form_Load or something like that. The form_load event
doesn't fire until you show the form so you should load up the items in
the Sub New function if you want them available right away.

Also, a better way to write this is probably to make a public readonly
property in frmMISRoutine that returns the arraylist you are looking
for. Better OO form.

hope this helps
Chris
 
marcmc said:
I don't get any errors but it never builds the array list. .. . .
Dim frmMISRoutine As New Routines

For Each Item As Object
In frmMISRoutine.ChkListBoxRoutines.Items
LogtoSet1.Add(Item)
Next

Are you loading these Items through the Designer, or at Run-Time?
If they're /not/ in the Designed form, then they won't be in the new
instance of the Form that you are creating when you execute
Dim frmMISRoutine As New Routines

You must get hold of a reference to the form that is already loaded
and, therefore, stands a rather better chance of having some values
in it.

Regards,
Phill W.
 
Thanks Chris

Chris said:
Yes you can access items like this from another form, although I think
OO guys would look down on it a little.

I assume you have make ChkListBoxRoutines a public control. If that's
the case then the reason that the array is never built is because
ChkListBoxRoutines.items is empty. do:

Debug.Writeline(frmMISRoutine.ChkListBoxRoutines.Count)

to check it. My guess would be that you are adding items to that
collection in the Form_Load or something like that. The form_load event
doesn't fire until you show the form so you should load up the items in
the Sub New function if you want them available right away.

Also, a better way to write this is probably to make a public readonly
property in frmMISRoutine that returns the arraylist you are looking
for. Better OO form.

hope this helps
Chris
 

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

Back
Top