473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Panel and Checkbox have been created and NullReferenceEx ception wasthrown ...

Hello

I've the following code

Panel pnlData = new System.Windows. Forms.Panel();
CheckBox checkBox = new System.Windows. Forms.CheckBox( );
checkBox.AutoSi ze = true;
checkBox.Dock = System.Windows. Forms.DockStyle .Top;
checkBox.Name = "checkBox";
checkBox.TabInd ex = 1;
checkBox.Text = "checkBox";
checkBox.UseVis ualStyleBackCol or = true;
try
{
pnlData.Contain er.Add(checkBox );
}
catch (NullReferenceE xception a)
{ }

And there the NullReferenceEx ception will be thrown alwas.

Can me someone tell why?

Thanks for all

Best regars
Wolfgang Uhr
Feb 9 '06 #1
4 3260
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.Contain er.Add(checkBox );

with:

pnlData.Control s.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.AutoSi ze = true;
checkBox.Dock = System.Windows. Forms.DockStyle .Top;
checkBox.Name = "checkBox";
checkBox.TabInd ex = 1;
checkBox.Text = "checkBox";
checkBox.UseVis ualStyleBackCol or = true;
try
{
pnlData.Contain er.Add(checkBox );
}
catch (NullReferenceE xception a)
{ }

And there the NullReferenceEx ception 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.mic rosoft.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.Contain er.Add(checkBox );

with:

pnlData.Control s.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.mic rosoft.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.Con tainer.Add(chec kBox), then the
command throws an error and if I use pnlTreeData.Con trols.Add(check Box),
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
1405
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 has typed in the textbox, the datagrid has been edited,(a user edits or inserts a new cell) a checkbox is checked.
3
4753
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 and disappear when the checkbox is unchecked. My code is: Private Sub checkBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles checkBox1.CheckedChanged
9
12547
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 Request.Form("CheckBox")(i)) > 0 then End If Next
1
1583
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> <asp:Panel id="pnlDocumentDetailsGrid" runat="server" Visible="False"> <TABLE id="Table112" cellSpacing="0" cellPadding="0" width="100%" border="0">
2
2170
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. The weird part is, the panel, in the instant it becomes visible, seems to have an image of what this panel had in it the LAST TIME THE APPLICATION WAS RUN! Since this panel is created anew every time the application is run ('natch), this seems...
5
8405
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) NewCheckbox.AutoSize = True NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0) NewCheckbox.Name = "Checkbox" & counter1 + 1
10
35964
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 implemented a Wizard which changes that number, as well as a save and load function to the program. I know the number of being altered in memory (i added a quick check button) but what i'm struggling with is how to refresh the panel with the new...
5
6125
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 suggestions. The one suggestion I've found that makes the most sense isn't working for me and after this most recent failure I'm really at a loss! ;0) I'm overriding WndProc and checking the Message.Msg property for the WM_KEYUP message. If anyone has...
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.