473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

TabControls TabPages collection cause error when removing pages

Hi,

I have created a UserControl which is subsequently hosted on a standard
form.
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):
myTabCtrl.TabPages.Clear();

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:
myTabCtrl.TabPages.Clear();

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?

Regards,
Peter
Nov 16 '05 #1
4 5879
Peter,

did you sort this out?
Why do you want to clear tabpages, when you don't have any to clear?
if you plan on calling this method as a refresh routine, say, where you want
to recreate the tab pages, then somethings wrong with the logic, because you
should create the pages once when the dialog is first initialised, then c#
will delete them all appropriately when your object is destroyed.

Daniel.

"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:OG**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have created a UserControl which is subsequently hosted on a standard
form.
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):
myTabCtrl.TabPages.Clear();

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:
myTabCtrl.TabPages.Clear();

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?

Regards,
Peter

Nov 16 '05 #2
Hi,

No I haven't sorted this out yet.

Whether this is logical or not it should be possible but for some reason
causes an error.

My reasons for wanting to clear the TabPages when refreshing (after some
config dialog changes) is because (a) I want to reuse as much code as
possible (b) I don't want to have to write lots of conditional code.

After the tab control is initially configured with the tab pages (and each
of
the tab pages with a richtextbox control) the first page has data streamed
into it's richtextbox. As a means of not getting what I don't want I only
do this for the first tab any other tabs do not get any data inserted into
them until the user clicks/views the page.

It is possible that the user may have viewed all pages when they change
some config options hence instead of adding conditional code and extra
methods to my pages to see if they need to change their data or simply
carry on fetching as the user scrolls the richtextbox I want to clear all
the
pages, recreate them and set the initial data for the first page (as my
Render() method already does).

Anyhow as my original post said the call to:
myTabCtrl.TabPages.Clear()
....fails with an object reference not set exception.
However initially when the control first loads and this line is executed
it works fine, go figure!

So the situation is thus:
I can clear the TabPagesCollection when it's empty but when it
has some pages in it I get the above error!

At present I have left this in the hope of getting a response here
whilst I work on another project.

Regards,
Peter
"Daniel Bass" <DanielBass TAKE at OUT CAPS WORDS Postmaster.co.uk> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Peter,

did you sort this out?
Why do you want to clear tabpages, when you don't have any to clear?
if you plan on calling this method as a refresh routine, say, where you want to recreate the tab pages, then somethings wrong with the logic, because you should create the pages once when the dialog is first initialised, then c#
will delete them all appropriately when your object is destroyed.

Daniel.

"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:OG**************@TK2MSFTNGP11.phx.gbl...
Hi,

I have created a UserControl which is subsequently hosted on a standard
form.
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):
myTabCtrl.TabPages.Clear();

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:
myTabCtrl.TabPages.Clear();

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?

Regards,
Peter


Nov 16 '05 #3
I am having a similar problem. I have several pages in the tab
control. When I do the .TabPages.Clear() I get a "Cannot find table
-1" error. Basically, I want to reuse the control. I simply want to
clear out the existing pages and add several new ones.

Any ideas?

Steven
Nov 16 '05 #4
meh
Hi Steven;
I'm not sure this will help but try....

tabControl1.TabPages.Remove()
meh

"Steven Cudd" <cu******@hotmail.com> wrote in message
news:c0**************************@posting.google.c om...
I am having a similar problem. I have several pages in the tab
control. When I do the .TabPages.Clear() I get a "Cannot find table
-1" error. Basically, I want to reuse the control. I simply want to
clear out the existing pages and add several new ones.

Any ideas?

Steven

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Tony Williams | last post by:
This is an extension of a previous post which has been answered for me, thanks to those who replied. But this is another request from my users.Is it possible to have a subform that has a tabcontrol...
2
by: Ray | last post by:
Hi I have designed a database app using a windows form and a tab control with comboboxes and edit controls on each tab control. The problem that I am having is with the edit form that I have...
4
by: Alexandre Soares | last post by:
Hi, On some pages, I put a collection in the session, which uses the InProc mode. On pages where the session is extensively used (many collections are put into it), whenever I try to remove an...
3
by: VJ | last post by:
Is there a way to Order Tabpages.. I tried to Use a Class that implements the IComparer and a Compare method as suggested in the MSDN article. "ArrayList.Sort()" and then use the instance of...
7
by: Richard | last post by:
I have a form with seven tapages. These span only one record with a large number of fields (textboxes). On Tabpage1 I display a number of read-only text boxes. This displays information about...
2
by: Kevin | last post by:
Although lots of people described how to workaround the lack of ability to hide and show tab pages on a tab control, I couldnt find a code example so I made one. Create a class that inherits from...
0
by: Sarmatia | last post by:
I'm stumped. I load add-ins at run time. Each Add-In has a collection of UserControls. These UserControls are then added to a TabControl as TabPages. The UserControls are created in the Add-In's...
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
0
by: Mike | last post by:
Hi, I have a collection object bound to a data grid, after I remove an item from the collection, the minute I click on the datagrid I get an error saying the specified argument was out of the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.