Embedded user controls

D

Dave Kelly

c#, .Net 2.0, VS2008

I have a user control, and wish to embed other custom/user controls
within this control.

I am getting problems in compilation though, that the type or
namespace cannot be found.

I have used the same namespace for both components.

Everything compiles and works fine with each of the respective user
controls used in the main project. The main control is derived from
TabPage, and one of the embedded controls is derived from CheckBox.

Any way of resolving this?
 
P

Peter Duniho

c#, .Net 2.0, VS2008

I have a user control, and wish to embed other custom/user controls
within this control.

I am getting problems in compilation though, that the type or
namespace cannot be found.

[...]
Any way of resolving this?

Undoubtedly.

You haven't really offered much in the way of specifics, but generally
speaking you'll get a compilation error like that if you've failed to
be specific enough about the namespace for some type you're using, or
you've failed to add a necessary reference to the project (under
"References" in the Solution Explorer).

If the former, you can solve that either by providing the fully
qualified name for the namespace before the type, or you can provide an
appropriate "using" statement at the beginning of the source file.

Not knowing the exact error, it's impossible to know what namespace or
reference hasn't been included. But it may be as simple as needing to
add a reference to the assembly for your custom control.

Pete
 
D

Dave Kelly

c#, .Net 2.0, VS2008
I have a user control, and wish to embed other custom/user controls
within this control.
I am getting problems in compilation though, that the type or
namespace cannot be found.
[...]
Any way of resolving this?

Undoubtedly.

You haven't really offered much in the way of specifics, but generally
speaking you'll get a compilation error like that if you've failed to
be specific enough about the namespace for some type you're using, or
you've failed to add a necessary reference to the project (under
"References" in the Solution Explorer).

If the former, you can solve that either by providing the fully
qualified name for the namespace before the type, or you can provide an
appropriate "using" statement at the beginning of the source file.

Not knowing the exact error, it's impossible to know what namespace or
reference hasn't been included. But it may be as simple as needing to
add a reference to the assembly for your custom control.

Pete

The situation is I have the source for both of the components in the
same project. Simplifying it, I have a control derived from the
TabPage, and another control derived from the CheckBox, which I wish
to programmatically place on the TabPage.

Both controls are in the same project, and using the same namespace.

I can use either control in any part of the project (eg put the
derived checkbox on the mainform), just not use it in the custom
tabpage control.

Note: I am not trying to solve the specifics of how to add the
checkbox derived control, but generically, as there are a few other
controls I wish to use on my derived TabPage.

Even when I tried to use a DLL of the custom controls, and referenced
the assembly in the project, I still got the same error.
 
P

Peter Duniho

[...]
Even when I tried to use a DLL of the custom controls, and referenced
the assembly in the project, I still got the same error.

As I wrote, this is usually not a difficult thing to fix. The
compilation error provides detailed information that should lead you to
a solution.

But you haven't provided enough information here for anyone else to
answer the question. The exact wording of the compilation error and a
concise-but-complete sample of code demonstrating the problem would be
required.

You claim that both controls are in the same project and in the same
namespace. If so, then you've either got a typo or a conflicting name
or you've failed to completely qualify a nested type or you're wrong
about them being in the same project and namespace. As you can see,
there are a variety of things that could cause the error you're
describing and so there's no way for anyone else to know which of those
problems is actually the issue as long as you continue to withhold the
important details.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top