473,412 Members | 2,054 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,412 software developers and data experts.

Panel and Checkbox have been created and NullReferenceException wasthrown ...

Hello

I've the following code

Panel pnlData = new System.Windows.Forms.Panel();
CheckBox checkBox = new System.Windows.Forms.CheckBox();
checkBox.AutoSize = true;
checkBox.Dock = System.Windows.Forms.DockStyle.Top;
checkBox.Name = "checkBox";
checkBox.TabIndex = 1;
checkBox.Text = "checkBox";
checkBox.UseVisualStyleBackColor = true;
try
{
pnlData.Container.Add(checkBox);
}
catch (NullReferenceException a)
{ }

And there the NullReferenceException will be thrown alwas.

Can me someone tell why?

Thanks for all

Best regars
Wolfgang Uhr
Feb 9 '06 #1
4 3224
Hey there Wolfgang,

The problem is that container is null when you are trying to add. I'm
assuming you are wanting to make the checkbox appear in the panel, in which
case you actually just need to replace:

pnlData.Container.Add(checkBox);

with:

pnlData.Controls.Add(checkBox);

and that will place you checkbox onto the panel control. Hope that helps!

"Wolfgang Uhr" wrote:
Hello

I've the following code

Panel pnlData = new System.Windows.Forms.Panel();
CheckBox checkBox = new System.Windows.Forms.CheckBox();
checkBox.AutoSize = true;
checkBox.Dock = System.Windows.Forms.DockStyle.Top;
checkBox.Name = "checkBox";
checkBox.TabIndex = 1;
checkBox.Text = "checkBox";
checkBox.UseVisualStyleBackColor = true;
try
{
pnlData.Container.Add(checkBox);
}
catch (NullReferenceException a)
{ }

And there the NullReferenceException will be thrown alwas.

Can me someone tell why?

Thanks for all

Best regars
Wolfgang Uhr

Feb 10 '06 #2
Hi Wolfgang,

Thanks for posting!

From the snippets of the current code, I have added the code into the Form
Load event in my own application. I can not reproduce the current issue
because all codes work fine. So I think maybe the null reference error is
related to the context for the current application. Could you please make a
simple demo and send it to me? This will help me to repro the current issue
and find some factors. My alias is v-****@online.microsoft.com (remove
..online). Thanks for your understanding!

I'm looking forward your reply.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Feb 10 '06 #3
Justin Swan (MSFT) schrieb:
pnlData.Container.Add(checkBox);

with:

pnlData.Controls.Add(checkBox);


Thank you very much this helps well.

Wolfgang Uhr
Feb 10 '06 #4
Yuan Ren[MSFT] schrieb:
Could you please make a
simple demo and send it to me? This will help me to repro the current issue
and find some factors. My alias is v-****@online.microsoft.com (remove
online). Thanks for your understanding!


I have just installed the very last Studio-Version 8.0.50727.42
(RTM.050727-4200) - German.

And realy: If I use pnlTreeData.Container.Add(checkBox), then the
command throws an error and if I use pnlTreeData.Controls.Add(checkBox),
the program works well.

I have used Container because this command will be used if i put a
Checkbox from the toolbox to the panel manually.

Ok, I'll use Container.

Best Regards
Wolfgang Uhr
Feb 10 '06 #5

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

Similar topics

1
by: Doug | last post by:
hello, i have got a panel with several controls in it, including a button which is disabled. I want to enable this button whenever, any of the controls inside the panel changes. e.g. someone...
3
by: *no spam* | last post by:
How do you refresh the controls on a panel? I've got a VB webform which contains a panel. On that panel is a checkbox and a textbox. I'd like the textbox to appear when the checkbox is checked...
9
by: Craig Andrews | last post by:
Hello, How do I access HTML CheckBoxs in the codebehind section of an ASP.NET program? In the old Interdev days one would: For i = 1 to Request.Form("CheckBox").Count if...
1
by: Manny Chohan | last post by:
Hi, i have a template column in datagrid. Inside template column i have panel. I want to control the visibility of the panel with checkbox. can this be done? <asp:TemplateColumn> <ItemTemplate>...
2
by: Peteroid | last post by:
When the application I'm working on is run it creates a panel with a Paint event customized to draw primitives (circles, rectangles, etc.), places the panel on a form, and then launches the form....
5
by: Mike Fellows | last post by:
I have created some checkboxes within a panel using the code below Dim NewCheckbox As New CheckBox Me.Panel2.Controls.Add(NewCheckbox) NewCheckbox.Location = New Point(XLocation, YLocation)...
10
by: markwalker84 | last post by:
Hello everyone! Got a bit of a problem... Two of the panels on my program contain a number of check boxes. The exact number of which is determined by a pair of variables. I have recently...
5
by: sklett | last post by:
I know that Panel (and most of it's derivitives) don't raise keyboard events. I *really* need to catch keyboard events though so I've been googling the topic and have found quite a few...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.