Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

Close tabpage of custom control

Hi All,

I want to close certain or all tab pages.

How could I do this ?

Thank you.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

You don't Close Tab Pages but instead you "Remove" them. Note this does NOT remove the page permanently, but rather just hides it.

YourTabControl.TabPages.Remove(0)

You can also use the TabPage Name:

YourTabControl.TabPages.Remove(tpCustomer)

Note that "tpCustomer" is the name of one of my TabPages. It is not a string value, so it's not enclosed in quotes.

See here for more information: https://msdn.microsoft.com/en-us/library/zb7xae05(v=vs.110).aspx
Avatar of PNRT
PNRT

Hi

When you say close I assume that you mean to remove?

In which case -

TabControl1.TabPages.Remove(TabPage1)

Will work

Good luck
Avatar of emi_sastra

ASKER

Hi All,

Please see the custom control code.

Thank you.
ERV_TAB_CONTROL.vb
What's the point of your code? I don't see where you've overridden the Remove function, so it should work as suggested.
I have tried this.

  For tpIndex = 0 To tc.TabPages.Count - 1
            tc.TabPages.RemoveAt(tpIndex)
        Next

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll

Additional information: Index 2 is out of range.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of PNRT
PNRT

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is how I add tab page.

 Dim tbp As New TabPage.
  tbcERPMain.TabPages.Add(tbp)
   tbp.Controls.Add(form)

            tbcERPMain.SelectedTab = tbp

Thank you.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi All,

It works.

Thank you very much for your help.