Switch between two TABs

Hi group, I have a TabPanel with 2 tabs, so index 0 and 1.
Now I would like to make that when I press a button, the first one with its focus is shown, and when I press another button, the second one is seen with its focus. I wrote this.

Button 1:

TabPanel1.Visible=True   
TabPanel1.SelectedPanelIndex=0
TabPanel1.RemovePanelAt(1)

Button 2:

TabPanel1.Visible=True
TabPanel1.SelectedPanelIndex=1
TabPanel1.RemovePanelAt(0)


if I press button 1 the right window starts.
if I press button 2 the right window starts.
But if I press 1 and then 2, or 2 and then 1, I get an error. Where am I wrong?

You don’t specify the error you get, you should always do that, it helps us helping you.

My guess is there is a clue with this line:

TabPanel1.RemovePanelAt(1)

Check in the doc what that method does.

that’s the problem, i can’t figure out where the problem is. Usually in Exception I find my problems, but now it’s 0.

Well first of all, don’t remove the panels. they automatically hide when another panel is shown, and you can get rid of the calls to make it visible unless it’s truly hidden.

Yes, now I was trying to eliminate the TabPanel1.RemovePanelAt(1) code, and it works, the panel is selected automatically and it doesn’t give me an error when changing. But can I hide the unused panel with a method other than TabPanel1.RemovePanelAt(1) ?

As Greg mentioned, panels and controls automatically hide when you switch visible panels. Anything that’s still shown after you change the SelectedPanelIndex isn’t actually on the panel.

Ok i solved. Thanks.