Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controls on TabControl are Hidden

Status
Not open for further replies.

swreng

MIS
Jun 22, 2006
90
GR
Dear all,

I have a tabcontrol with 2 tabpages and 3 textboxes in each tabpage.
Now i am trying to retrive the visible property from the controls in order to execute some more commands according to the result of the visibility (true,false):

int i,j;

for(i=0;i<TabControl1.TabPages.Count;i++)
{
for(j=0;j<TabControl.TabPages.Controls.Count;j++)
{
if(TabControl.TabPages.Controls[j].Visible==true)
{
// execute some commands


}

else
{

// execute other command
// The code always is entering here
// but i can see the objects with my eyes



}
}
}



Many thanks
 
This is a bit odd.

you use in your first forloop : TabControl1

then in your second forloop: TabControl

and then in your if statement: TabControl

Was this a copy error or something?
 
Hi Jurkmonkey

This is a copy error on the post. My TabControl's name is TabControl1.

Thank you for your reply.
 
The documentation for the .Visible property says this:

VS 2005 Documentation said:
Gets or sets a value indicating whether the control and all its parent controls are displayed.

In this instance only one of the tabs will be visible, so only three of the text boxes will be visible.

If you set the .Visible property to false while the tab it is on is hidden, it does have the effect of not showing the control when the tab is selected. Setting .Visible to true does not have the effect of showing the tab but does ensure the control is shown when the tab is selected.
 
I knew those damn tabcontrols were funny.

a quick way around this is to:

1. set TabControl1.SuspendLayout();

TabPage selectedpage = TabControl1.SelectedPage;

for(i=0;i<TabControl1.TabPages.Count;i++)
{
for(j=0;j<TabControl.TabPages.Controls.Count;j++)
{
TabControl1.SelectedPage = TabControl1.TabPages; //or whatever the property is to set the tab visible
if(TabControl.TabPages.Controls[j].Visible==true)
{
// execute some commands


}
... //your else statement and so on

TabControl1.SelectedPage = selectedpage;

TabControl1.ResumeLayout();
 
Hi again,

I try the above solution of JurkMonkey but doesn't work in VS 2003.
The visible property=false and i can't see the textboxes on the tabpages.

With the code i wrote the visible property=false but i can see it.

I thing that something is not going good with that control.

Best Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top