Reference the calling form.

  • Thread starter Thread starter William Oliveri
  • Start date Start date
W

William Oliveri

Is there a way to reference a calling form and pass an object to it?

This is what I'm trying to do:

Form A creates new instance of Form B and then calls it modal.
Form B creates a new instance of PersonalInfo class, makes a call to the db
and fills that class

Here's the tricky part:

I now want to pass the PersonalInfo object to the calling form (Form A) so
it can display this retrieved information.


I was thinking it would be something like: FormB.ParentForm.PersonalInfoObj
= FormA.PersonalInfoObj

but this doesn't seem to work.

Thanks in advance,

Bill
 
Sorry, that should be:

I was thinking it would be something like:
FormB.ParentForm.PersonalInfoObj = FormB.PersonalInfoObj
 
Hi, William Oliveri
How about doing something like this?

'Inside FormA
With New FormB
.Owner = Me
.ShowDialog()
End With

'Inside FormB
CType(Me.Owner, FormA).Button1.Text = "Hello World"

Hope that helps.

From,
Hon Yuen, Ng
 
William,

Although I would not do that do I think that what you ask will be possible.

In formA
\\\
dim formB as frmB
frmB.showdialog
dim b as dataset = frmB.a
frmB.Dispose
///
In formB
\\\
Public a as new dataset
///

Your problem will probably be, that the GC has more problems than needed,
because dataset a in frmB will only be garbaged when it is not used anymore
in frmA.

Therefore quickly typed something as
\\\
dim formB as frmB
dim a as new dataset
frmB.a = a
frmB.Dispose
///
And than in frmB
\\\
public a as dataset
///
Has my preference

Just my idea

Cor
 
William Oliveri said:
Is there a way to reference a calling form and pass an object to it?

What you need in 'Form2' is a reference to your instance of 'Form1'. You
can pass the reference to 'Form1' in a property when showing 'Form2' from
'Form1':

Code for 'Form1':

\\\
Dim f As New Form2()
f.Form1 = Me
f.Show()
///

Code for 'Form2':

\\\
Private m_Form1 As Form1

Public Property Form1() As Form1
Get
Return m_Form1
End Get
Set(ByVal Value As Form1)
m_Form1 = Value
End Set
End Property
///

You can access 'Form1''s properties inside 'Form2' with 'Me.Form1', for
example, 'Me.Form1.Button1.Text = "Bla"'.

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>
 

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