"Parent" or "Owning" Form of a "Sub-Form"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eBob.com

    "Parent" or "Owning" Form of a "Sub-Form"

    How does a "sub-form", i.e. one invoked by another form, determine anything
    about the form which brought it into existence, i.e., I suppose,
    instantiated it? I wanted to so something like this ...

    MsgBox("called by " & Owner.Name)

    .... but that throws a null reference exception. Parent.Name and
    ParentForm.Name also throw null reference exceptions. Form1.Name works -
    but that's not very flexible.

    My MsgBox, above, is in the constructor of the "sub-form".

    Thanks, Bob


  • rowe_newsgroups

    #2
    Re: "Parent&qu ot; or "Owning&qu ot; Form of a "Sub-Form"

    On Sep 18, 2:15 pm, "eBob.com" <eBob....@total lybogus.comwrot e:
    How does a "sub-form", i.e. one invoked by another form, determine anything
    about the form which brought it into existence, i.e., I suppose,
    instantiated it?  I wanted to so something like this ...
    >
    MsgBox("called by " & Owner.Name)
    >
    ... but that throws a null reference exception.  Parent.Name and
    ParentForm.Name also throw null reference exceptions.  Form1.Name works-
    but that's not very flexible.
    >
    My MsgBox, above, is in the constructor of the "sub-form".
    >
    Thanks,  Bob
    If you want to show the message box from the constructor, you're most
    likely going to need to pass in a reference to the creating from as a
    parameter.

    I wonder however if you mean you want to know what form showed the
    "sub-form". In which case the message box should live in the "Show"
    and "ShowDialog " method, but be warned it might only work if you use
    the overloaded call that passes in the owning form.

    Thanks,

    Seth Rowe [MVP]

    Comment

    • Family Tree Mike

      #3
      Re: &quot;Parent&qu ot; or &quot;Owning&qu ot; Form of a &quot;Sub-Form&quot;

      If it is an MdiChild, the it can call MdiParent.Name. If as you suggest you
      are just doing a ShowDialog type of call, then you could use a StackTrace
      object.

      "eBob.com" <eBob.com@total lybogus.comwrot e in message
      news:uBViGqbGJH A.3392@TK2MSFTN GP05.phx.gbl...
      How does a "sub-form", i.e. one invoked by another form, determine
      anything about the form which brought it into existence, i.e., I suppose,
      instantiated it? I wanted to so something like this ...
      >
      MsgBox("called by " & Owner.Name)
      >
      ... but that throws a null reference exception. Parent.Name and
      ParentForm.Name also throw null reference exceptions. Form1.Name works -
      but that's not very flexible.
      >
      My MsgBox, above, is in the constructor of the "sub-form".
      >
      Thanks, Bob
      >

      Comment

      • eBob.com

        #4
        Re: &quot;Parent&qu ot; or &quot;Owning&qu ot; Form of a &quot;Sub-Form&quot;

        >"rowe_newsgrou ps" <rowe_email@yah oo.comwrote in message
        >news:9588d6b f-a5a6-43ab-b0d7-e5c979d99645@m4 5g2000hsb.googl egroups.com...
        >On Sep 18, 2:15 pm, "eBob.com" <eBob....@total lybogus.comwrot e:
        >How does a "sub-form", i.e. one invoked by another form, determine
        >anything
        >about the form which brought it into existence, i.e., I suppose,
        >instantiated it? I wanted to so something like this ...
        >>
        >MsgBox("call ed by " & Owner.Name)
        >>
        >... but that throws a null reference exception. Parent.Name and
        >ParentForm.Nam e also throw null reference exceptions. Form1.Name works -
        >but that's not very flexible.
        >>
        >My MsgBox, above, is in the constructor of the "sub-form".
        >>
        >Thanks, Bob
        >
        >If you want to show the message box from the constructor, you're most
        >likely going to need to pass in a reference to the creating from as a
        >parameter.
        >
        >I wonder however if you mean you want to know what form showed the
        >"sub-form". In which case the message box should live in the "Show"
        >and "ShowDialog " method, but be warned it might only work if you use
        >the overloaded call that passes in the owning form.
        >
        >Thanks,
        >
        >Seth Rowe [MVP]
        >http://sethrowe.blogspot.com/
        Hi Seth,

        What I am after is the name of the form which did the

        Dim sform as new SomeForm

        i.e. in SomeForm code I want to get the name of who New'ed me. Maybe the
        same code will Show me maybe it won't. Maybe it already has maybe it never
        will.

        Although I ran into the problem in constructor code it seems to me that it
        is a general problem. MsgBox has nothing to do with the problem, I was just
        using it to experiment and to illustrate the problem. In general I would
        say that it is a bad programming practice to try to get at any information
        about your creator (unless it is explicitly passed). But I think that there
        might be exceptions such as Location (which is what I was after).

        What really makes me curious is what Parent, ParentForm, and Owner mean
        since not a one of them means what I would have guessed.

        Thanks, Bob


        Comment

        Working...