Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Not able to open sub form from main form.

Posted on 2008-10-09
11
Medium Priority
?
375 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:Tekati68
  • 5
  • 5
11 Comments
 
LVL 18

Expert Comment

by:Priest04
ID: 22682832
Make sure that both LoadUserAdmin and UserAdmin are in the same namespace.

Goran
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22682835
surely you have a namespace problem. Review your main form and useradmin implementation files and check which namespace each belong to.
0
 
LVL 18

Accepted Solution

by:
Priest04 earned 1000 total points
ID: 22682848
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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 1000 total points
ID: 22682856
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
 
LVL 18

Expert Comment

by:Priest04
ID: 22682992
:)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22683037
hmm, just noticed we are writing at the same time (well, me some seconds late).
0
 
LVL 18

Expert Comment

by:Priest04
ID: 22683099
not a problem, it was just funny, that we wrote in the same time same things both times. :)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22683128
>>it was just funny, that we wrote in the same time same things both times.
That sound sounds like a double-check answer!
0
 
LVL 2

Author Comment

by:Tekati68
ID: 22683540
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
 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 1000 total points
ID: 22683584
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
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 1000 total points
ID: 22683689
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

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question