Using inner controls from a tab page control

Using inner controls from a tab page control

Post by pnp » Wed, 02 Jun 2004 18:06:32


I have a tab control and in each tab a custom control. All the custom
controls (different amongst them) have a common function.
What I want to do is when a user clicks on a tab, I want the function of the
control in the tab page to be called. Is there a way to do this without
using a switch statement or an if statement?

Something like this.Tab_Management.SelectedTab.Controls[0] ...
 
 
 

Using inner controls from a tab page control

Post by Jeff Mastr » Wed, 02 Jun 2004 19:47:01

Have all of your custom controls implement an interface that contains
the method you want to call when a tab is clicked. You can then loop
through a tab's controls after a click and find the one that implements
your interface.

Something like this (untested) code...

foreach( Control c in targetTab.Controls )
{
if( c is IMyTabControl )
{
IMyTabControl myTabCtl = c as IMyTabControl;
myTabCtl.MyMethod();
}
}

Regards,
-Jeff