Re: sabarad_arun@hotmail.com
- From: "Bruce Wood" <brucewood@xxxxxxxxxx>
- Date: 5 Aug 2005 11:31:30 -0700
I don't see why it would become recursive. Perhaps I don't understand
what you're trying to do.
The way I see it, you have several possible scenarios:
1. You know the number of user controls ahead of time, since you're
placing them directly on your form in the Designer anyway. In this
case, the simplest solution is the one that I suggested:
private void okButton_Click(object sender, System.EventArgs e)
{
this.userControl1.StoreResults();
this.userControl2.StoreResults();
this.userControl3.StoreResults();
this.userControl4.StoreResults();
}
No recursion there.
2. You're adding the user controls to your form dynamically, so you
can't know ahead of time how many you will need to call. In this case
you have two possible ways to solve the problem.
The first method (which is ugly, in my opinion) is to iterate through
all of the controls, looking for the kind of user control that you need
to call, and then call it:
private void okButton_Click(object sender, System.EventArgs e)
{
foreach (Control c in this.Controls)
{
MyUserControl uc = c as MyUserControl;
if (uc != null)
{
uc.StoreResults();
}
}
}
The other solution is to create some sort of registration system, by
which the form keeps track of the user controls added to it, and then
has the OK button Click event iterate through the subscription list:
public void AddUserControl(MyUserControl uc)
{
this.Controls.Add(uc);
this._userControlList.Add(uc);
}
private void okButton_Click(object sender, System.EventArgs e)
{
foreach (MyUserControl uc in this._userControlList)
{
uc.StoreResults();
}
}
I none of these solutions works for you, could you describe your
problem in more detail?
.
- Follow-Ups:
- Re: sabarad_arun@hotmail.com
- From: sabarad_arun
- Re: sabarad_arun@hotmail.com
- References:
- sabarad_arun@hotmail.com
- From: sabarad_arun
- Re: sabarad_arun@hotmail.com
- From: Bruce Wood
- Re: sabarad_arun@hotmail.com
- From: sabarad_arun
- sabarad_arun@hotmail.com
- Prev by Date: Re: calling a COM function
- Next by Date: Re: IErrorInfo in .NET
- Previous by thread: Re: sabarad_arun@hotmail.com
- Next by thread: Re: sabarad_arun@hotmail.com
- Index(es):