Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: The variable 'ucComp1' is either undeclared or was never assign 2

Status
Not open for further replies.

eb24

Programmer
Dec 17, 2003
240
US
I've been receiving some errors lately and have tried recreating my controls, but I seems to be getting the same error again!

Here's my scenario (in simplest terms): I have a simple form named frmV that has a UserControl named ucComp1. I get the error when I Ctrl+F5: The variable 'ucComp1' is either undeclared or was never assigned. This points to line 66 on my frmV.Designer.cs file.
Code:
65: this.Controls.Add(this.ucComp1);
66: this.Name = "frmV";
FYI, here is my code for the frmV.cs file:
Code:
   public partial class frmV : Form
    {
        public frmV()
        {
            InitializeComponent();
        }

        public ucComp UC
        {
            get { return ucComp1;  }
        }
    }
I'm stumped and can't seem to move forward now. Any and all assistance will be greatly appreciated.
 
find out where ucComp1 is declared.

should be something like

YourUserControl ucComp1 = new YourUserControl();

It is possible that the disgner deleted this component on you - gotta love MS
 
Thanks for your quick reply. As per your response, it does seem that my designer does indeed have that declaration. This is some of the my code within the designer:
Code:
        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ucFeature1 = new UserControls.ucFeature();
            this.SuspendLayout();
            // 
            // ucFeature1
            // 
            this.ucFeature1.AutoSize = true;
            this.ucFeature1.Location = new System.Drawing.Point(13, 13);
            this.ucFeature1.Name = "ucFeature1";
            this.ucFeature1.Size = new System.Drawing.Size(678, 643);
            this.ucFeature1.TabIndex = 0;
            // 
            // frmFeature
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(395, 364);
            this.Controls.Add(this.ucFeature1);
            this.Name = "frmFeature";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();
        }
        #endregion
        private ucFeature ucFeature1;
Any and all suggestions will be greatly appreciated.
 
ucComp is not instantiated anywhere in the code you posted.

Add the code that JurkMonkey posted, either in the constructor, or in the InitializeComponent routine.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Wait...

Don't put the code in the InitializeComponent method directly. If you mess with that code Visual Studio will start eating your designer code and bad things happen.

Either re-add the usercontrol from the designer (and the code will show up in initializecomponent itself) or add it in a separate method called by the constructor.
 
Now I know what I was doing wrong - it seems that as JurkMonkey suggested, if I start messing with the Designer code manually, dirty things start happening (VS 2005).

I have since avoided Designer changes and everything seems to be fine!

Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top