Trying To Call Child Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven C

    Trying To Call Child Form

    Hello:

    I've seen several recent threads on this, but I'm still not clear how
    to reference a *method* on one form from another. I want to add a
    customer in the child form, and then update the customers grid in the
    parent form.

    frmCustomers is the parent, and frmAddCustomer is the child. In
    frmCustomers, when the user clicks the ADD commandbutton, I call this
    code:

    private void cmdAdd_Click(ob ject sender, System.EventArg s e)
    {
    Conferro.Forms. frmAddCustomer. frmAddCustomer
    frmAddCustomer = new
    Conferro.Forms. frmAddCustomer. frmAddCustomer( );
    frmAddCustomer. p_ofrmCustomers = this;
    frmAddCustomer. Show();
    }


    And in the frmAddCustomer form, I have a public property set up as
    follows:



    public object p_ofrmCustomers
    {
    get
    {
    return p_ofrmCustomers ;
    }
    set
    {
    object p_ofrmCustomers = value;
    }
    }

    I'm then trying to call the m_refreshcustom ersgrid() method as
    follows, to refresh the grid on the parent, and then release the child
    form:

    public void DisposeForm()
    {
    this.p_ofrmCust omers.m_refresh customersgrid() ; <==
    this.Dispose();
    }

    This doesn't work. I get the "object does not contain definition"
    error on compile.

    What am I doing wrong here? Sorry, newbie question. In Foxpro, this
    is easy, as there is an implicit reference to any instantiated object.

    Thanks!

    Steven
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Trying To Call Child Form

    Steven,

    p_ofrmCustomers is a reference to type Object, so it doesn't know about
    your m_refreshcustom ersgrid method. Basically, you have to change the type
    of the p_ofrmCustomers property to the type of the child form, and then the
    definition will be apparent.

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m


    <Steven C> wrote in message
    news:qhsf90tg4i c09nrjrcqm26tbl 7nj188g6i@4ax.c om...[color=blue]
    > Hello:
    >
    > I've seen several recent threads on this, but I'm still not clear how
    > to reference a *method* on one form from another. I want to add a
    > customer in the child form, and then update the customers grid in the
    > parent form.
    >
    > frmCustomers is the parent, and frmAddCustomer is the child. In
    > frmCustomers, when the user clicks the ADD commandbutton, I call this
    > code:
    >
    > private void cmdAdd_Click(ob ject sender, System.EventArg s e)
    > {
    > Conferro.Forms. frmAddCustomer. frmAddCustomer
    > frmAddCustomer = new
    > Conferro.Forms. frmAddCustomer. frmAddCustomer( );
    > frmAddCustomer. p_ofrmCustomers = this;
    > frmAddCustomer. Show();
    > }
    >
    >
    > And in the frmAddCustomer form, I have a public property set up as
    > follows:
    >
    >
    >
    > public object p_ofrmCustomers
    > {
    > get
    > {
    > return p_ofrmCustomers ;
    > }
    > set
    > {
    > object p_ofrmCustomers = value;
    > }
    > }
    >
    > I'm then trying to call the m_refreshcustom ersgrid() method as
    > follows, to refresh the grid on the parent, and then release the child
    > form:
    >
    > public void DisposeForm()
    > {
    > this.p_ofrmCust omers.m_refresh customersgrid() ; <==
    > this.Dispose();
    > }
    >
    > This doesn't work. I get the "object does not contain definition"
    > error on compile.
    >
    > What am I doing wrong here? Sorry, newbie question. In Foxpro, this
    > is easy, as there is an implicit reference to any instantiated object.
    >
    > Thanks!
    >
    > Steven[/color]


    Comment

    • Steven C

      #3
      Re: Trying To Call Child Form


      Excellent! Many thanks. This is what I was doing incorrectly. One
      additional thing, and I'll stop buggin' ya. I'm getting a stack
      overflow error when this property is being read. The property
      accessor was changed to this:

      public Conferro.Forms. frmCustomers.fr mCustomers p_ofrmCustomers
      {
      get
      {
      return p_ofrmCustomers ;
      }
      set
      {
      Conferro.Forms. frmCustomers.fr mCustomers
      p_ofrmCustomers = value;
      }
      }

      which allows it to be properly set. However, when I use the property
      per the below, I get a stack overflow error.

      public void DisposeForm()
      {
      this.p_ofrmCust omers.m_refresh customersgrid() ; <==
      this.Dispose();
      }

      This would have worked like a charm in the venerable old Foxpro.


      Thanks!

      Steven
      [color=blue]
      >On Tue, 4 May 2004 16:07:30 -0400, "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote:[/color]
      [color=blue]
      >Steven,
      >
      > p_ofrmCustomers is a reference to type Object, so it doesn't know about
      >your m_refreshcustom ersgrid method. Basically, you have to change the type
      >of the p_ofrmCustomers property to the type of the child form, and then the
      >definition will be apparent.
      >
      > Hope this helps.[/color]

      Comment

      • Jim Hughes

        #4
        Re: Trying To Call Child Form

        p_ofrmCustomers is the Property Name. By Setting/Getting to itself it
        results in an endless recursive loop until the stack overflows. Without
        discussing your variable / property naming conventions, add a private
        variable ( here prepended with an _ ) and set/get it instead of the property
        name itself.

        private Conferro.Forms. frmCustomers.fr mCustomers _p_ofrmCustomer s;
        public Conferro.Forms. frmCustomers.fr mCustomers p_ofrmCustomers
        {
        get
        {
        return _p_ofrmCustomer s;
        }
        set
        {
        Conferro.Forms. frmCustomers.fr mCustomers
        _p_ofrmCustomer s = value;
        }
        }

        <Steven C> wrote in message
        news:080g901bm3 9e5nqs7j9aclgpi 35lt3jmn0@4ax.c om...[color=blue]
        >
        > Excellent! Many thanks. This is what I was doing incorrectly. One
        > additional thing, and I'll stop buggin' ya. I'm getting a stack
        > overflow error when this property is being read. The property
        > accessor was changed to this:
        >
        > public Conferro.Forms. frmCustomers.fr mCustomers p_ofrmCustomers
        > {
        > get
        > {
        > return p_ofrmCustomers ;
        > }
        > set
        > {
        > Conferro.Forms. frmCustomers.fr mCustomers
        > p_ofrmCustomers = value;
        > }
        > }
        >
        > which allows it to be properly set. However, when I use the property
        > per the below, I get a stack overflow error.
        >
        > public void DisposeForm()
        > {
        > this.p_ofrmCust omers.m_refresh customersgrid() ; <==
        > this.Dispose();
        > }
        >
        > This would have worked like a charm in the venerable old Foxpro.
        >
        >
        > Thanks!
        >
        > Steven
        >[color=green]
        > >On Tue, 4 May 2004 16:07:30 -0400, "Nicholas Paldino [.NET/C# MVP]"[/color][/color]
        <mvp@spam.guard .caspershouse.c om> wrote:[color=blue]
        >[color=green]
        > >Steven,
        > >
        > > p_ofrmCustomers is a reference to type Object, so it doesn't know[/color][/color]
        about[color=blue][color=green]
        > >your m_refreshcustom ersgrid method. Basically, you have to change the[/color][/color]
        type[color=blue][color=green]
        > >of the p_ofrmCustomers property to the type of the child form, and then[/color][/color]
        the[color=blue][color=green]
        > >definition will be apparent.
        > >
        > > Hope this helps.[/color]
        >[/color]


        Comment

        • Steven C

          #5
          Re: Trying To Call Child Form

          Dooh!

          Thanks, Jim.

          BTW, what's the preferred naming convention for a property? I'm using
          the convention many Foxpro developers use.

          Thanks again;

          Steven
          [color=blue]
          >On Tue, 4 May 2004 14:18:11 -0700, "Jim Hughes" <NOSPAMJ3033@Ho tmail.com> wrote:[/color]
          [color=blue]
          >p_ofrmCustomer s is the Property Name. By Setting/Getting to itself it
          >results in an endless recursive loop until the stack overflows. Without
          >discussing your variable / property naming conventions, add a private
          >variable ( here prepended with an _ ) and set/get it instead of the property
          >name itself.
          >
          >private Conferro.Forms. frmCustomers.fr mCustomers _p_ofrmCustomer s;
          >public Conferro.Forms. frmCustomers.fr mCustomers p_ofrmCustomers
          >{
          >get
          >{
          >return _p_ofrmCustomer s;
          >}
          >set
          >{
          >Conferro.Forms .frmCustomers.f rmCustomers
          >_p_ofrmCustome rs = value;
          >}
          >}
          >
          ><Steven C> wrote in message
          >news:080g901bm 39e5nqs7j9aclgp i35lt3jmn0@4ax. com...[color=green]
          >>
          >> Excellent! Many thanks. This is what I was doing incorrectly. One
          >> additional thing, and I'll stop buggin' ya. I'm getting a stack
          >> overflow error when this property is being read. The property
          >> accessor was changed to this:
          >>
          >> public Conferro.Forms. frmCustomers.fr mCustomers p_ofrmCustomers
          >> {
          >> get
          >> {
          >> return p_ofrmCustomers ;
          >> }
          >> set
          >> {
          >> Conferro.Forms. frmCustomers.fr mCustomers
          >> p_ofrmCustomers = value;
          >> }
          >> }
          >>
          >> which allows it to be properly set. However, when I use the property
          >> per the below, I get a stack overflow error.
          >>
          >> public void DisposeForm()
          >> {
          >> this.p_ofrmCust omers.m_refresh customersgrid() ; <==
          >> this.Dispose();
          >> }
          >>
          >> This would have worked like a charm in the venerable old Foxpro.
          >>
          >>
          >> Thanks!
          >>
          >> Steven
          >>[color=darkred]
          >> >On Tue, 4 May 2004 16:07:30 -0400, "Nicholas Paldino [.NET/C# MVP]"[/color][/color]
          ><mvp@spam.guar d.caspershouse. com> wrote:[color=green]
          >>[color=darkred]
          >> >Steven,
          >> >
          >> > p_ofrmCustomers is a reference to type Object, so it doesn't know[/color][/color]
          >about[color=green][color=darkred]
          >> >your m_refreshcustom ersgrid method. Basically, you have to change the[/color][/color]
          >type[color=green][color=darkred]
          >> >of the p_ofrmCustomers property to the type of the child form, and then[/color][/color]
          >the[color=green][color=darkred]
          >> >definition will be apparent.
          >> >
          >> > Hope this helps.[/color]
          >>[/color]
          >[/color]

          Comment

          • Ed Courtenay

            #6
            Re: Trying To Call Child Form

            Steven C wrote:
            [color=blue]
            > Dooh!
            >
            > Thanks, Jim.
            >
            > BTW, what's the preferred naming convention for a property? I'm using
            > the convention many Foxpro developers use.
            >
            > Thanks again;
            >
            > Steven[/color]

            The MSDN site has an excellent section on Naming Guidelines at


            In particular, to directly address your query, the guidelines for
            Properties are found at:




            Comment

            Working...