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

Adding usercontrols to other usercontrols

Hi,

I'm developing a GUI with almost all Usercontrols. It's been working
wonderfull up till a few weeks ago, and really crashed yesterday.

Suddenly I can no longer add some of my usercontrols to any of the others
(I've also tried to create new usercontrols and windowforms and add them to
the new control, but that doesn't work any better). It's really frustrating
since I've been able to add them and run the program before.

To debug I've put some messageboxes in my constructors of the uc beeing
added, and it seems to go just fine, so now I'm wondering where the
errormessage comes from. The error being "Object reference not set to an
instance of an object".

The only variable holding an object in the usercontrol is a variable that
holds a reference to another usercontrol, but that is instanciated in
runtime, and is only declared in the header. I've tried to assign it a new
instance, but it doesn't change the outcome and the error still appears. I
have a few variables that have get-set-methods in the usercontrol to be able
to set unique ID-numbers in designtime on the usercontrol thery're placed,
but they're one of system definied types (string, bool and int).

I've been searching the web for others with this problem but unfortunaly
only find people who's forgotten the = new object declaration. So to
summarize:

1. I try to drag a usercontrol (ucChild) on to another usercontrol (ucParent)
2. It goes through the ucChilds constructor without a problem
3. Just as ucParent is about to show the ucChild something happens and I get
to see: "An exception occurred while trying to create an instance of
myUserControl. The exception was 'Object reference not set to an instance of
an object.'". (I can see the ucChild-size show up in the ucParent and
dissappear just before the error message shows up.

So even if the error message says it has to do with my ucChild, I'm starting
to think that it's on the ucParents rePaint (or somewhere else) it just goes
wrong. Any ideas, anyone?

/Emma
Nov 16 '05 #1
2 1413
Hi Emma,

The best would be if could post some working sample that demonstrates the
problem. I understand that your project could be rather big to post it in a
ng, but at least you can post the stack trace of the exception.
Or if you want to you can send me some part of the project that demonstrates
the problem at guzzev(at)yahoo(dot)com.

BTW if it happens (as I understant it is) at design time you can debug

You can start a new instance of VS.
Open the project in this instace.( now you have the project open twise)
In one of the insances go to 'Debug' menu and click on "Processes..." in the
dialog attach the debuger to the other VS
You can set exception settings to stop on all exceptions. You can set some
breakpoints as well. In the second VS add the user control to the parent and
so on.

This can be done via the projects setting but as long as you don't write
designers this method of debugging is better for your needs, I believe

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Emma" <Em**@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
Hi,

I'm developing a GUI with almost all Usercontrols. It's been working
wonderfull up till a few weeks ago, and really crashed yesterday.

Suddenly I can no longer add some of my usercontrols to any of the others
(I've also tried to create new usercontrols and windowforms and add them
to
the new control, but that doesn't work any better). It's really
frustrating
since I've been able to add them and run the program before.

To debug I've put some messageboxes in my constructors of the uc beeing
added, and it seems to go just fine, so now I'm wondering where the
errormessage comes from. The error being "Object reference not set to an
instance of an object".

The only variable holding an object in the usercontrol is a variable that
holds a reference to another usercontrol, but that is instanciated in
runtime, and is only declared in the header. I've tried to assign it a new
instance, but it doesn't change the outcome and the error still appears. I
have a few variables that have get-set-methods in the usercontrol to be
able
to set unique ID-numbers in designtime on the usercontrol thery're placed,
but they're one of system definied types (string, bool and int).

I've been searching the web for others with this problem but unfortunaly
only find people who's forgotten the = new object declaration. So to
summarize:

1. I try to drag a usercontrol (ucChild) on to another usercontrol
(ucParent)
2. It goes through the ucChilds constructor without a problem
3. Just as ucParent is about to show the ucChild something happens and I
get
to see: "An exception occurred while trying to create an instance of
myUserControl. The exception was 'Object reference not set to an instance
of
an object.'". (I can see the ucChild-size show up in the ucParent and
dissappear just before the error message shows up.

So even if the error message says it has to do with my ucChild, I'm
starting
to think that it's on the ucParents rePaint (or somewhere else) it just
goes
wrong. Any ideas, anyone?

/Emma

Nov 16 '05 #2
Hi Goutsev,

Thank you for a quick reply. Unfortunately the project is rather extensive,
with four projects and a lot of references to our own dll:s.

We're working on breaking out some code at the moment, if the problem still
persists tomorrow when that part should be done, I'll try to make an example
solution with only two - three usercontrols and post it here.

If you come up with some other bright ideas until then - don't hesitate to
tell me.

/Emma

"Stoitcho Goutsev (100) [C# MVP]" wrote:
Hi Emma,

The best would be if could post some working sample that demonstrates the
problem. I understand that your project could be rather big to post it in a
ng, but at least you can post the stack trace of the exception.
Or if you want to you can send me some part of the project that demonstrates
the problem at guzzev(at)yahoo(dot)com.

BTW if it happens (as I understant it is) at design time you can debug

You can start a new instance of VS.
Open the project in this instace.( now you have the project open twise)
In one of the insances go to 'Debug' menu and click on "Processes..." in the
dialog attach the debuger to the other VS
You can set exception settings to stop on all exceptions. You can set some
breakpoints as well. In the second VS add the user control to the parent and
so on.

This can be done via the projects setting but as long as you don't write
designers this method of debugging is better for your needs, I believe

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Emma" <Em**@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
Hi,

I'm developing a GUI with almost all Usercontrols. It's been working
wonderfull up till a few weeks ago, and really crashed yesterday.

Suddenly I can no longer add some of my usercontrols to any of the others
(I've also tried to create new usercontrols and windowforms and add them
to
the new control, but that doesn't work any better). It's really
frustrating
since I've been able to add them and run the program before.

To debug I've put some messageboxes in my constructors of the uc beeing
added, and it seems to go just fine, so now I'm wondering where the
errormessage comes from. The error being "Object reference not set to an
instance of an object".

The only variable holding an object in the usercontrol is a variable that
holds a reference to another usercontrol, but that is instanciated in
runtime, and is only declared in the header. I've tried to assign it a new
instance, but it doesn't change the outcome and the error still appears. I
have a few variables that have get-set-methods in the usercontrol to be
able
to set unique ID-numbers in designtime on the usercontrol thery're placed,
but they're one of system definied types (string, bool and int).

I've been searching the web for others with this problem but unfortunaly
only find people who's forgotten the = new object declaration. So to
summarize:

1. I try to drag a usercontrol (ucChild) on to another usercontrol
(ucParent)
2. It goes through the ucChilds constructor without a problem
3. Just as ucParent is about to show the ucChild something happens and I
get
to see: "An exception occurred while trying to create an instance of
myUserControl. The exception was 'Object reference not set to an instance
of
an object.'". (I can see the ucChild-size show up in the ucParent and
dissappear just before the error message shows up.

So even if the error message says it has to do with my ucChild, I'm
starting
to think that it's on the ucParents rePaint (or somewhere else) it just
goes
wrong. Any ideas, anyone?

/Emma


Nov 16 '05 #3

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

Similar topics

2
by: Chien Lau | last post by:
I frequently define internal UserControl-derived classes in my WinForms apps: internal class MyUserControl:UserControl{ ... } I'll often need to embed these controls in a Form, whose class...
4
by: Anders K. Jacobsen [DK] | last post by:
Hi I have some common UserControls i want to share between to sites (on the same mashine but on diffrent virtual paths). right now i have on solution file with aprox 10 projects. 2 of these is...
2
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page...
3
by: YYZ | last post by:
I swear I've done my research, and now I was just hoping someone could explain this to me. I've got a base class (usercontrol) that I am using just as an interface. Meaning, I've defined...
3
by: Bart Van Hemelen | last post by:
I'm working on a project where the user of a site will receive custom content, depending on a set of parameters. The content will all be contained in UserControls (.ascx), that will be used as...
4
by: hula | last post by:
Hello i have a problem with adding usercontrols to a panel. I use a panel to add up to 20 usercontrols to a panel that has autoscrol enabled. The number of usercontrols to add, and the data...
4
by: Nathan Sokalski | last post by:
In several of my UserControls I add properties. If I access these properties in the CodeBehind of the pages that use the controls, I recieve an error when compiling. The reason for this is because...
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
6
by: alun65 | last post by:
I'm having trouble programmatically adding a user control and then setting some of it's server controls. I add the user control to the code behind and add it to a placeholder: protected void...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
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,...

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.