CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Extend Tabpage

  1. #1
    Join Date
    May 2008
    Posts
    66

    Extend Tabpage

    Hi all!

    I create a class named TabPageEx which extends TabPage.

    In my app, sometimes it is necessary to get the selected tab from the TabControl ( I named this object as tcDataPanes) in order to add some controls.

    I tried to cast from but it does not work.
    Code:
                tabpage1 = new TabPageEx();
                tabpage1 = (TabPageEx)tcDataPanes.SelectedTab;
    An InvalidCastExpection message appears at runtime.

    All tabpages that were created are TabPageEx' type. Each tabPageEx object has a FlowLayoutPanel, and there is a method at TabPageEx which returns this container to my app.

    What is wrong?

    Thank you in advance!

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Extend Tabpage

    This link should be helpful :
    http://www.dotnetrix.co.uk/tabcontrols.html

  3. #3
    Join Date
    May 2008
    Posts
    66

    Re: Extend Tabpage

    This link was very helpful, wih it I solve some other problems which I had.

    But, the problem which generates this thread persists.
    This code line continues generating an InvalidCastExpection .

    This is the class TabPageEx which I coded:
    Code:
        public class TabPageEx : System.Windows.Forms.TabPage {
    
            FlowLayoutPanel flowLayoutPanel1;
    
            public TabPageEx() : base () { 
            }
    
            public TabPageEx(System.Windows.Forms.TabControl tcDataPanes) : base () {
    
                tcDataPanes.TabPages.Add("New tab");
            }
        }
    }
    The situation that the error described in the first message occurs is when I try to retrieve the selected tab page in order to add a new control.

    Any ideas? How can I solve it?

    Thank you in advance!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured