473,372 Members | 980 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,372 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 5883
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...
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.