Not able to open sub form from main form.

I have a main form called Receiving and I am trying to open a new form that I created using Project Add Windows Form with the name of UserAdmin.

This is the function from the main form.

        private void LoadUserAdmin_Click(object sender, EventArgs e)
        {
            UserAdmin ua = new UserAdmin();
        }

The issue is that UserAdmin which is the correct name of the second form is not recognized in the main form and I am getting errors of.

The type of namespace name 'UserAdmin' could not be found (are you missing a using directive or an assembly reference?)
private void LoadUserAdmin_Click(object sender, EventArgs e)
{
     UserAdmin ua = new UserAdmin();
}

Open in new window

LVL 2
Tekati68Asked:
Who is Participating?
 
Priest04Connect With a Mentor Commented:
if, for example, UserAdmin is in a different namespace, then you should either

1) import this namespace with the using keyword at the beggining of the class

using MyNameSpace;

or

2) write a fully qualified name for the UserAdmin form. Example


private void LoadUserAdmin_Click(object sender, EventArgs e)
{
    MyNameSpace.UserAdmin ua = new MyNameSpace.UserAdmin();
}

Open in new window

0
 
Priest04Commented:
Make sure that both LoadUserAdmin and UserAdmin are in the same namespace.

Goran
0
 
Jaime OlivaresSoftware ArchitectCommented:
surely you have a namespace problem. Review your main form and useradmin implementation files and check which namespace each belong to.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
in case UserAdmin belongs to another namespace, you can do also:

private void LoadUserAdmin_Click(object sender, EventArgs e)
{
     othernamespace.UserAdmin ua = new othernamespace.UserAdmin();
}
0
 
Priest04Commented:
:)
0
 
Jaime OlivaresSoftware ArchitectCommented:
hmm, just noticed we are writing at the same time (well, me some seconds late).
0
 
Priest04Commented:
not a problem, it was just funny, that we wrote in the same time same things both times. :)
0
 
Jaime OlivaresSoftware ArchitectCommented:
>>it was just funny, that we wrote in the same time same things both times.
That sound sounds like a double-check answer!
0
 
Tekati68Author Commented:
That was the issue and much appreciated.  One final question though all of the examples I have seen have not refered to the NameSpace like that so can you please tell me what I did wrong in the first place.  Where did I go wrong to start with?
0
 
Priest04Connect With a Mentor Commented:
Could be you have firstly created one form, then changed the namespace, then created another form. Or, you have placed you second form in a folder, so folder name is added to namespace. When you create two forms in the same project, in the same location, they both hsve same namespace by default.
0
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
indeed you can change the namespace "by hand" even if you accidentally created with an undesired namspace.

You have to modify 2 files:
yourform.cs
yourform.designer.cs

there you will find:

using someNS;
using otherNS;

namespace theFormNS
{
       public [partial] class YourFormClass
       {
              // etcera

Then you have to change in both files: theFormNS to your desired namespace
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.