Avatar of yaronusa
yaronusa asked on

inherited control not recognized in c# csharp .net

I created an inherited TreeView control I call WaferTreeView. After creating it, I see it available in my toolbox. I then drag it onto my main form, and it is autmatically called WaferTreeView1.

Once I look at any other file in my project, I cannot view my main form in design view, because of this listed error: "The variable 'waferTreeView1' is either undeclared or was never assigned."

I only dragged and dropped the inherited WaferTreeView onto the form, and like any other control, I expect the designer to have the code it needs to make it work.

Upon examining the designer code of the form containing the WaferTreeView control, I noticed that the WaferTreeView type is unknown (in black instead of light blue color).

Why is this?? What should I do? Please help.
// Can't view main form because of this error:
// The variable 'waferTreeView1' is either undeclared or was never assigned.
 
 
// As you can see below, 'waferTreeView1' IS declared and assigned:
namespace MainForm
{
  partial class frmGridTester
  {
    ...
    private void InitializeComponent()
    {
      ...
      this.waferTreeView1 = new WaferTree.WaferTreeView();
      this.table.Controls.Add(this.waferTreeView1, 0, 1);
      ...
    }
    
 
    // WaferTreeView is an unknown type (therefore shown in
    // black color instead of light blue). WHY??
    private WaferTreeView waferTreeView1;
    
  }
}
 
 
namespace WaferTree
{
  public partial class WaferTreeView : TreeView
  {
 
    public WaferTreeView(): base()
    {
      InitializeComponent();
    }
  
    ...
  }
 
  public class WaferTreeNode : TreeNode
  {
    ...
  }
}

Open in new window

.NET ProgrammingC#

Avatar of undefined
Last Comment
pvginkel

8/22/2022 - Mon
pvginkel

For some very strange reason it has omitted the namespace with the declaration. The problem you have is that C# cannot find the type. What mistifies me though is why it has omitted the namespace. It did add it with the instantiation.

Changing the declaration to the following should of course solve your problem:

private WaferTree.WaferTreeView waferTreeView1.
ASKER
yaronusa

That helps, but it still won't let me view my main form, as it sites the same error I mentioned in my question.
I even tried taking out every line mentioning WaferTreeView, but the error is still there, not letting me view my form.

What should I do?
ASKER CERTIFIED SOLUTION
pvginkel

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
yaronusa

The error I get is: "The variable 'waferTreeView1' is either undeclared or was never assigned."

I tried re-staring VS, also recompiling and rebuilding, nothing worked.

I found an earlier backup of my project and I copied the main form file and its designer counterpart to my project (overwriting the same files that already existed).

I restarted my project, re-dragged my custom control onto the form, and the first thing I did was check the designer. Oddly, now it says WaferTree.WaferTreeView WafterTreeView 1, just as you suggested.

Moreover, I can now view my form! Then I modified my custom control, rebuilt the project, and I can still view my form! as well as run the program... go figure... :)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
pvginkel

Incredible. The mysteries of Visual Studio.

Watched a presentation a few days ago. They said Visual Studio contains millions and millions of lines of code. There must be a bug in one of them :).