1

I am using a tabcontrol, i want to remove a particular tab from the control. The value i have to do this in a string which i dynamically.

How to remove the tab from tabcontrol using a existing tab name which i have in a string ??

The problem i am facing is..

I tried to use tabcontrol1.tabpages.remove(tabpage name);

In the above syntax i need to pass the tabpage name, but i have the value in a string.

2 Answers 2

3

Do you have the tab page name or the tab page text?

If it is the name:

string tabToRemove = "tabPageName";
for (int i = 0; i < myTabControl.TabPages.Count; i++)
{
    if (myTabControl.TabPages[i].Name.Equals(tabToRemove, StringComparison.OrdinalIgnoreCase))
    {
        myTabControl.TabPages.RemoveAt(i);
        break;
    }
}

If it is the text, you would simply use the Text property instead of the Name property.

Sign up to request clarification or add additional context in comments.

Comments

2

it seems that when you add a tabpage you use: tabControl1.TabPages.Add(string text)
Either try using: tabControl.TabPages.Add(string key, string text) then remove tabpages by key : tabControl1.TabPages.Remove(string key) (you can set key = tabpage text if they are all distinct)

or create a function that will find a tab by it's text:

    TabPage tp;
    foreach (TabPage ttp in tabControl1.TabPages)
    {
        if (ttp.Text == "tab text") tp = ttp;
        break;
    }
    tabControl1.TabPages.Remove(tp); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.