473,394 Members | 1,956 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,394 software developers and data experts.

Nested tabcontrol - error - Object reference not set to an instance of an object.

mshmyob
904 Expert 512MB
I am using VS2008 and vb.net

I have a nested tabcontrol.

tabControl 1 and tabControl3

In tabControl3 I am trying to populate a text control with a value from a control placed on tabControl1.

Expand|Select|Wrap|Line Numbers
  1. ' add a savings tabpage
  2. Dim strSavingsPage As String
  3. Dim dblTaxRate As Double
  4. dblTaxRate = Me.txtRetirementTaxRate.Text
  5.        For Each tabpg As TabPage In SavingsAllTabPages
  6.             If Not TabControl3.Contains(tabpg) Then
  7.                 TabControl3.TabPages.Add(tabpg)
  8.                 tabpg.Text = "Savings"
  9.                 tabpg.Focus()
  10.                 strSavingsPage = Mid(tabpg.Name, 11)
  11.                 Me.Controls("txtWithdrawRate" & strSavingsPage).Text = dblTaxRate
  12.                 Exit For
  13.             End If
  14.         Next
  15.  
The error occurs on the following line:
Expand|Select|Wrap|Line Numbers
  1. Me.Controls("txtWithdrawRate" & strSavingsPage).Text = dblTaxRate
  2.  
If I change the line to

Expand|Select|Wrap|Line Numbers
  1. Me.txtWithdrawRate1.Text = dblTaxRate
  2.  
everything works fine.

The complete error is:

NullReference exception was unhandled
Object reference not set to an instance of an object.

I am probably doing something obvious but vb.net is not my strong point.

Any ideas?

cheers,
Apr 7 '11 #1

✓ answered by mshmyob

Got it Rabbit.

You do have to refer to the original container. replaced the line in question with the following 2 lines

Expand|Select|Wrap|Line Numbers
  1. Dim cntlYou As Control = tabpg.Controls("grpYou" & strSavingsPage).Controls("grpTaxable" & strSavingsPage).Controls("txtWithdrawRate" & strSavingsPage)
  2. cntlYou.Text = dblTaxRate
  3.  
I also had it all inside another group box so I had to reference that container also.

Thanks for all your help, I appreciate it.

cheers,

6 2809
Rabbit
12,516 Expert Mod 8TB
Are you sure strSavingsPage is outputting correctly? Did you do a message box to output the value and length to make sure it's correct?
Apr 7 '11 #2
mshmyob
904 Expert 512MB
Hello Rabbit,

Yeah that was the first thing I did. I again just verified it and the value is correct.

cheers,
Apr 7 '11 #3
Rabbit
12,516 Expert Mod 8TB
Does this work?
Me.Controls("txtWithdrawRate1").Text = dblTaxRate
Apr 8 '11 #4
mshmyob
904 Expert 512MB
Nope - same error.

I have tried referencing the control as far back as the forms container but still have the same error.

This is driving me crazy. As a work around I am currently using a SELECT CASE but would rather bring it down to this single statement.

cheers,
Apr 8 '11 #5
mshmyob
904 Expert 512MB
I am thinking it has something to do with referencing the complete container. Maybe I am not getting the sequence correct.

Lets assume names like so:

Form = form1
main tabControl = tabControl1
main tabcontrol page index = 1 (ie: 2nd page)
nested tabcontrol = tabControl2
nested tabcontrol page index = 0 (ie: 1st page)
groupbox = group1
textbox control = textbox1

How would I create the complete reference to the textbox control starting with the form container? The textbox is in the groupbox container on the first tab page of the nested tabcontrol.

cheers,
Apr 8 '11 #6
mshmyob
904 Expert 512MB
Got it Rabbit.

You do have to refer to the original container. replaced the line in question with the following 2 lines

Expand|Select|Wrap|Line Numbers
  1. Dim cntlYou As Control = tabpg.Controls("grpYou" & strSavingsPage).Controls("grpTaxable" & strSavingsPage).Controls("txtWithdrawRate" & strSavingsPage)
  2. cntlYou.Text = dblTaxRate
  3.  
I also had it all inside another group box so I had to reference that container also.

Thanks for all your help, I appreciate it.

cheers,
Apr 8 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
6
by: NewToDotNet | last post by:
I am getting "Object reference not set to an instance of an object. " when I attempt to open a C# windows service class in design view, although I was able to initially create the service and open...
4
by: Moe Sizlak | last post by:
Hi There, I have a user control that has 2 listmenus populated from a database, I want the form to submit when the listmenu are changed which seems to happen no problem when the page is on it's...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
3
by: nemo | last post by:
Hi, My application works fine on the localhost but spits this error as soon as I put it on the server. I know this error occurs when an object has not been instantiated prior to a reference, but...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
7
by: Brett | last post by:
I'm not sure why I keep getting this error, "Object reference not set to an instance of an object". Private Function somefunction() as string Dim MyCurrentClass As New Class1 Try For i As...
6
by: kalaivanan | last post by:
hi, i am a beginner in c#. i have theoretical knowledge about object, reference and instance. but i want to know clearly about what is an object, reference and instance. can any one help me? or...
2
by: rksadhi | last post by:
/*Geting error ---object reference not set to an instance---at bold line----plz reply asap thanks in advance*/ cmd = new OleDbCommand ("SELECT e.emp_id,e.email, m.email AS Email FROM emp_details...
0
by: crystalelle | last post by:
Hi, I am facing trouble with the following code. Public Class Form1 Private PreviousTab As TabControl Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.