Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When a tabpage is created with the designer it is easy to remove like that:

Me.TabControl100.TabPages.Remove(TabPage130)

How do I remove a tabpage which was created with code?
My problem is that I cannot remove it without knowing the name of the tabpage.

What I have tried:

Me.TabPages.Remove("TabPage1")
Me.TabPages.Remove("TabPage2")
or
Me.TabPages.Remove(TabPage2)

that does not work because a tabpage control is expected and not a string.

What else can I do?
Posted
Updated 26-Oct-20 9:38am

1 solution

You don't need its "name", you need the instance of a tabpage that you want to remove.

When you created it, you used the New keyword, and stored the result in a variable - that value is the instance, and that's what you want to remove later.
So store the instance somewhere so you can get at it when you need it for removal! (Or if you are removing it as a result of tabpage event, the Sender event parameter will be the tabpage instance.
 
Share this answer
 
Comments
Jo_vb.net 26-Oct-20 15:58pm    
Great - that works fine.

Thank you.
OriginalGriff 27-Oct-20 3:16am    
You're welcome!

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