none
TabPages.Insert Bug?

    Question

  • Is anyone else out there having problems inserting TabPages?

    I thought it might be a problem in my main project, so I created a new WinForms test project, dropped a tabcontrol on the form, and added a line to insert a tab at position 0. Nothing else. My constructor looks like this:



    public Form1()
    {
       InitializeComponent();
       this.tabControl1.TabPages.Insert(0, "Test");
    }

     


    But when I run I only get the two tabs the designer adds by default.  I've tried all kinds of other permutations and still nothing.  No errors, but no inserted tab either.

    Thoughts?

    Friday, December 09, 2005 7:06 PM

Answers

  • The TabControl's handle must be created for the Insert method to work. You can do the insert in the Load event of the Form, or force handle creation like so:

    IntPtr h = this.tabControl1.Handle;
     

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"
    Friday, December 09, 2005 7:49 PM

All replies

  • The TabControl's handle must be created for the Insert method to work. You can do the insert in the Load event of the Form, or force handle creation like so:

    IntPtr h = this.tabControl1.Handle;
     

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"
    Friday, December 09, 2005 7:49 PM
  • Thanks Mark, that did the trick. Maybe put a word in the MSDN team's ear to put that in the documentation?
    Friday, December 09, 2005 8:03 PM
  • I personally feel that this is a bug in the tab control so I opened a bug for it.

    -mark
    Friday, December 09, 2005 8:10 PM
  •  Mark Rideout wrote:
    I personally feel that this is a bug in the tab control so I opened a bug for it.

    -mark

    Hi Mark,

    Do you have any idea if that bug have been corrected or not.

    I am developping an application for 3 month now and we use an tab control and using the insert() method, but since yesterday the insert just stop working, even if I didn't make any change in the methods calling that... I've try your fix and solve the problem, but not a great idea to hardcoded some bug patch in my patch....

    Friday, December 15, 2006 6:10 PM
  • I am using .NET framework 3.5 version , this bug still exists. Does anyone has any idea about this??
    Thursday, August 05, 2010 5:45 AM
  • I'm using .NET 4.0 and the bug is still there. 
    Thursday, February 17, 2011 9:29 AM
  • I can reproduce this bug too. 
    Sunday, April 14, 2013 1:20 AM
  • Wow, that original post was in 2005. This is now late 2013 and that bug is *still* in the latest .NET environments as of Sept 2013. I just tested ".NET Framework 4" and ".NET Framework 4 Client Profile" today (2013-09-19).
    • Proposed as answer by HerbF Wednesday, January 15, 2014 3:38 PM
    Thursday, September 19, 2013 6:17 PM
  • I proposed this as an answer in the probably vain hopes they will fix this...

    -herb

    Wednesday, January 15, 2014 3:38 PM