C# removing tabpage from tabcontrol

C# removing tabpage from tabcontrol

Post by mariushe » Thu, 02 Oct 2003 18:28:16

well I have an MDI window. inside the window there's a tabcontrol. when
remove tabpages from the tabcontrol (this.tabControl.TabPages.Remove(page))
then the window cannot be closed with "x" button. does anybody know, what's
the reason? why the on_close event isn't invoked?

1. DotNet 1.1 - C# - TabControl;TabPage;CheckedListBox

2. TabControls TabPages collection cause error when removing pages


I have created a UserControl which is subsequently hosted on a standard
My control has a TabControl on it but it has no TabPages configured.
At runtime I create X pages and put a single RichTextBox on each page.

In my controls loaded event I call my Render() method which configures
everything appropriately. When setting up the TabControl the first thing
it says is (not real var names):

for (int i = 0; i < someInt; i++)
...create page
... add page to tab control
... add richtextbox to page

On my control there is a button which pops up a configuration dialog
whereby various settings that affect the usercontrol can be set.
Due to this I have to reinitialise by usercontrol when the dialog closes.

So thus when returning from it I call my Render() method.
When it gets to the line:

I get an "object reference not set to an instance of an object"
exception occur. I tried changing the line to:

if (myTabCtrl.TabPages.Count != 0) myTabCtrl.TabPages.RemoveAt(0);

...which will work in my test data's case; this again causes an object
not set error.

Anybody have any ideas why I can call the Clear() method when there
are no pages, but when I call it when there are I get the above error?


3. Minor bug in TabControl.TabPages.Remove().

4. Anyway of Forcing a Specifc TabPage in a Tabcontrol to Display

5. Working with tabcontrol and tabpage

6. setting the order of TabPages in a TabControl

7. TabControl-TabPages

8. TabControl Refer To TabPage By Name

9. How to "disable" a TabPage of a TabControl?

10. TabControl/TabPage visual styles in XP

11. TabControl/TabPage VisibleChanged event problem

12. ComboBox in a TabPage of a TabControl

13. Retrieving active TabPage in a TabControl

14. TabPage & TabControl BackColor

15. TabControl.Select(TabPage) does not trigger Selecting Event