Reference the calling form.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • William Oliveri

    Reference the calling form.

    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.ParentFor m.PersonalInfoO bj
    = FormA.PersonalI nfoObj

    but this doesn't seem to work.

    Thanks in advance,

    Bill


  • William Oliveri

    #2
    Re: Reference the calling form.

    Sorry, that should be:

    I was thinking it would be something like:
    FormB.ParentFor m.PersonalInfoO bj = FormB.PersonalI nfoObj





    Comment

    • Hon Yuen, Ng

      #3
      Re: Reference the calling form.

      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

      Comment

      • Cor Ligthert

        #4
        Re: Reference the calling form.

        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




        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Reference the calling form.

          "William Oliveri" <wuji@bigvalley .net> schrieb:[color=blue]
          > Is there a way to reference a calling form and pass an object to it?[/color]

          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.Butto n1.Text = "Bla"'.

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

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          Working...