Multiple projects

Hello folks

As I just started to discover C# Express this is probably a very basic problem :blush: :

I started up a new windows application project. I would like to use the SourceGrid Control (http://www.devage.com/Wiki/ViewArticle.aspx?name=sourcegrid&version=0) within my application.

So I added the provided projects using add -> existing project. So far so good, the added projects are being displayed in the project explorer.

The next thing I want to do is to create an instance of one of the classes in the newly added projects. I tried it with the using directive:
using SourceGrid; This however does not work and an error is being thrown:
"The type or namespace "SourceGrid" could not be found..."

I read through the C#-Help articles about multiple projects, and how to add them to an existing project but did not find something about the problem above...

What am I doing wrong?
Thanks a lot!
[971 byte] By [Marcel.Kummer] at [2007-11-20 11:08:09]
# 1 Re: Multiple projects
did you add it as a refrence to the project too or just add the using ?
Rudegar at 2007-11-9 11:36:23 >
# 2 Re: Multiple projects
Hi !

Reading your post I got the idea that you really need to get the basic basics. So I would suggest you to work with an easy book like MS Visual C# 2005 Step by Step from the beginning to the very very end before trying to to bigger projects. I also had started now one year ago and as I had experience with VB and a bit C++ You will be learning very fast this way and all this basics are no problem after this. Namespaces have basically nothing to do with creating instances. It has to do with .. NAMESPACES ...I'll give you an easy definition A namespace keyword is used to declare a scope. This scope lets you organize code and gives you a way to create globally-unique types. If you have two different namespaces e.g nameaspace A and namespace B code and variables, classes ... of namespace A are unknown in namespace B.

If you want to use a method myMethod() of namespace B in namespace A you can do it like

B.myClassB.myMethodInB()
Or you may add the namespace to your project by using the 'using' directive

using B

namespace A{

public class myClassA {
...
// and in this class in any method then
private void MethodInMyClass(){
xyz = myClassB.myMethodInB() // without the namespace

}
}
}
[code]When using 'using' directive you dont need to explicitly tell of which namespace the method is. ( there is one exception when you have the same class and method in namespace A too. Then you need to do like the following to get the compiler informed which class and method you ware needing.
[code]
using B

namespace A{

public class myClass {
...
// and in this class in any method then
private void MethodInMyClass(){
xyz = B.myClass.myMethodB(); // here we use the namespace
abc = A.myClass.myMethodA();
}
}
}


If a namespace is in a dll then additionally you need to add the dll as a reference to the project.

Instances of classes for the difference of that are built using the 'new' keyword
[code]
MyClassB myB = new MyClassB()
[code]Got it ? But I really would suggest you reading an easy beginnersbook.
JonnyPoet at 2007-11-9 11:37:23 >
# 3 Re: Multiple projects
Dear Jonny Poet

Thanks for the detailled answer!
I will take your advice to heart and read through some basic documentation.

However I had already tried your first suggestion:
using B

namespace A{

public class myClassA {
...
// and in this class in any method then
private void MethodInMyClass(){
xyz = myClassB.myMethodInB() // without the namespace

}
}
}
But I did not come to the point where I want to create an instance of a class - say myClassB - from the newly added project:
Doing the using-statement already performed the error I mentioned.

Thanks for your kind help.
Marcel
Marcel.Kummer at 2007-11-9 11:38:22 >
# 4 Re: Multiple projects
Its me again :)

I just found out that adding the project automatically created the new controls in the toolbox menu. I can use these controls straight away without using any using directive.
Marcel.Kummer at 2007-11-9 11:39:28 >
# 5 Re: Multiple projects
Its me again :)

I just found out that adding the project automatically created the new controls in the toolbox menu. I can use these controls straight away without using any using directive.If you add projects together and they are of type WindowsControllLybrary ( Userdefind Controls ) then you may see this controls in the toolbox and you can drag them to your projects Form. Look into the designer and you will see that they are addressed there using the exact namespace and class where they are from And you also can use all enumerations, methods, whatever by defining the namespace everytime explicit, or you will be able to use the 'using' directive and then you can access this namespace members all without explicitly writing the namespace.

In the designer you can see all the code created to get a new instance of any control. Studying the automatic created code is very helpful to see how controls needs to be initialized and how namespaces explicitly are called, because in the designer there are usually all controls explicitly called.

You have talked abaout an error which occured ? In the older post I can see a namespace SourceGrid The question is: Does this namespace really exist or did you set the name of a control as the name of a namespace ?? Looking into your different projects you will see which namespaces exists and which not. A classname ha normally very less to do with a namespace.

For example if you look into my DoxkingPanel project you will find namespaces like DockingControls, DockingControls.Forms, DockingControls.Classes, DockingConrols.Buttons and so on and in the DockingControls.Forms namespace you will find Classes like DockablePanel DockableForm, TransparentForm while in the general namespace DockableControls you can find Dockingmanager, DockingControler...

So by the idea you see there is some connection why they are all in a specific namespace. I have grouped them together by their logic.

A namespace contains classes classes have Properties, have Methods and can throw Events.

By connecting projects together they normally are referenced together simple by having hem coupled together. THis way you will see them in the toolsbox as soon as you have compiled the controls section without troubles. You will see that selectiong a project you can each of the projects compile without the others. ( As long as you are compiling projects that doesnt use one of the other projects )

Example: Prpoject A is my mainproject which will use project B, C and D
Project B uses project D as its baselibrary too.
so you are able to compile project D without all the others ( you can compile it even when you have errors in Project A ) You can also compile project C without all the others But if you want to compile B or A you need that project D is without errors in before. Because both needs a compiled version of D to work.

namespaces doesn't very often creates an error. Normally look to typos C# is case sensitive !
Generally:
You cannot use a namespace, which doesn't exist.
Another point with compiling projects which are coupled together is:

If you try to compile the mainproject A it will have a look on B,C and D and if necessary recompiling them ( They get dirty flags when you change some code in them ) When one of this compilation fails all of it fails. If you have understood this you have learned a lot about how it works.
JonnyPoet at 2007-11-9 11:40:28 >