Click to See Complete Forum and Search --> : Extend Tabpage


gborges
June 12th, 2008, 03:44 PM
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.

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!

HanneSThEGreaT
June 13th, 2008, 01:06 AM
This link should be helpful :
http://www.dotnetrix.co.uk/tabcontrols.html

gborges
June 16th, 2008, 03:01 PM
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:

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!