Trying To Call Child Form

  • Thread starter Thread starter Steven C
  • Start date Start date
S

Steven C

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(object sender, System.EventArgs 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_refreshcustomersgrid() method as
follows, to refresh the grid on the parent, and then release the child
form:

public void DisposeForm()
{
this.p_ofrmCustomers.m_refreshcustomersgrid(); <==
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
 
Steven,

p_ofrmCustomers is a reference to type Object, so it doesn't know about
your m_refreshcustomersgrid 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.
 
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.frmCustomers p_ofrmCustomers
{
get
{
return p_ofrmCustomers;
}
set
{
Conferro.Forms.frmCustomers.frmCustomers
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_ofrmCustomers.m_refreshcustomersgrid(); <==
this.Dispose();
}

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


Thanks!

Steven
 
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.frmCustomers _p_ofrmCustomers;
public Conferro.Forms.frmCustomers.frmCustomers p_ofrmCustomers
{
get
{
return _p_ofrmCustomers;
}
set
{
Conferro.Forms.frmCustomers.frmCustomers
_p_ofrmCustomers = value;
}
}

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.frmCustomers p_ofrmCustomers
{
get
{
return p_ofrmCustomers;
}
set
{
Conferro.Forms.frmCustomers.frmCustomers
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_ofrmCustomers.m_refreshcustomersgrid(); <==
this.Dispose();
}

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


Thanks!

Steven
 
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
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.frmCustomers _p_ofrmCustomers;
public Conferro.Forms.frmCustomers.frmCustomers p_ofrmCustomers
{
get
{
return _p_ofrmCustomers;
}
set
{
Conferro.Forms.frmCustomers.frmCustomers
_p_ofrmCustomers = value;
}
}

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.frmCustomers p_ofrmCustomers
{
get
{
return p_ofrmCustomers;
}
set
{
Conferro.Forms.frmCustomers.frmCustomers
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_ofrmCustomers.m_refreshcustomersgrid(); <==
this.Dispose();
}

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


Thanks!

Steven
 
Steven said:
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

The MSDN site has an excellent section on Naming Guidelines at
http://msdn.microsoft.com/library/d...en-us/cpgenref/html/cpconnamingguidelines.asp

In particular, to directly address your query, the guidelines for
Properties are found at:
http://msdn.microsoft.com/library/d.../cpconPropertyNamingGuidelines.asp?frame=true
 

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