Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi everyone..

I'm new here. i got a little problem with tab controlling.here is the problem...
I've added a new tab control with 3 tabs to my form. i want to hide tabpage2 on default view so I wrote tabpage2.dispose() method in formload event.
now I want to view that page by clicking a button placed in tabpage1.(tabpage1 is the default view) so i wrote,


1. tabpage2.show();
2. tabcontrol.selectedtab = tabpage2;
3. tabpage2.select();


but I couldn't get that tabpage again.so, what should I do now??
Posted

Use the Hide function instead of dispose. Dispose simply mark it for garbage collection and then it is not available for call

Improved Answer

You can do like this example.

C#
public partial class Form1 : Form
{
    TabPage t1;
    private void Form1_Load(object sender, EventArgs e)
    {
        t1 = tabControl1.TabPages[1];
        tabControl1.TabPages.RemoveAt(1);
    }
    private void button1_Click(object sender, EventArgs e)
    {
        tabControl1.TabPages.Insert(1, t1);
    }
}
 
Share this answer
 
v2
Comments
d_lucifer 9-Mar-11 8:31am    
you mean tabpage2.hide(); function ?? it doesn't work friend. that's why I used dispose() function.I thought it's a hiding method.
Albin Abel 9-Mar-11 9:18am    
Look at my improved answer. It is better you should know what Dispose() function does
Manfred Rudolf Bihy 9-Mar-11 9:27am    
If you don't reply to the commenter he will not be notified. Please make a reply to d_lucifer comment out of the comment you made to your own answer.
Albin Abel 9-Mar-11 9:31am    
I did Manfred, Thanks.
d_lucifer 9-Mar-11 9:42am    
Finally, I got an answer.. yeah.. it works.. but still there is a little thing. if you click that button more than one time, you can have more tabs. well.. we can overcome that problem by adding
** tabcontrol1.SelectedTab = t1; ** line to the button click code..

by the way, thanks for your help... :) :)
First of all, the Dispose method will release all the resources, thus losing all the data.
If you want to hide a tabpage you should call the Hide method.

For further information please check MSDN
 
Share this answer
 
Comments
d_lucifer 9-Mar-11 8:31am    
you mean tabpage2.hide(); function ?? it doesn't work friend. that's why I used dispose() function.I thought it's a hiding method.
Ryan Zahra 9-Mar-11 8:38am    
Instead of hiding the tab, you can change the tabcontrol.SelectedIndex to a tabpage of your liking.
d_lucifer 9-Mar-11 8:46am    
yes i can do it.. but the thing is they are two completely different fields. (registration and payments) so i don't want to mix up them.
only after the registration(tabpage1) is done we are able to see the payments tab(tabpage2)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900