Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4534152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:14:43+00:00 2026-05-21T14:14:43+00:00

I have a grid of labels. In order to access them in a programmatically

  • 0

I have a grid of labels. In order to access them in a programmatically sensible manner, I changed them from:

gridLabel1
gridLabel2
...
gridLabelN

To:

gridLabel[0]
gridLabel[1]
...
gridLabel[N-1]

But now the designer is complaining that

The variable ‘gridLabel’ is either undeclared or was never assigned.

Despite the fact that I also changed this:

private System.Windows.Forms.Label gridLabel1 = new System.Windows.Forms.Label;
private System.Windows.Forms.Label gridLabel2 = new System.Windows.Forms.Label;
...
private System.Windows.Forms.Label gridLabelN = new System.Windows.Forms.Label;

To:

private System.Windows.Forms.Label[] gridLabel = new System.Windows.Forms.Label[N];

What have I missed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:14:43+00:00Added an answer on May 21, 2026 at 2:14 pm

    Don’t mess around with generated code yourself. The designer.cs file is supposed to be managed by the forms-designer itself, not by the user. In particular, it’s easy to test that the designer does not tolerate the procedure you appear to be following:

    1. Declaring a field of an array of controls to the designer file.
    2. Using this field to populate the form’s control-collection by modifying the generated InitializeComponent method.

    When I do so, I get the same error that you do.

    The usual solution for this sort of requirement is to use a programmatic technique to add a number of controls to a parent-control’s control-collection. Ideally, create your own user-control that can hold a number of Labels (which it populates programmatically). Then, you can use this control on your form with full designer support.

    EDIT:

    For example (sketch only, without the user-control), add a FlowLayoutPanel to the form via the designer.

    Then change the form’s constructor to:

    public MyForm()
    {
        InitializeComponent();
    
        var labels = Enumerable.Range(0, 100)
                               .Select(i => new Label { Text = i.ToString() })
                               .ToArray();
    
        flowLayoutPanel1.Controls.AddRange(labels);
    }
    

    Obviously, such a solution may not be appropriate if you don’t want the labels organized in a flow-layout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid of UIImageViews. The images names come from a sqlite3 database.
I have a simple grid layout which is just hosting several labels and textboxes.
I have created a java program that shows a grid of buttons and labels
I have a situation where I render items from server in GWT grid on
I am using vb.net code. I have grid view, please see the code below:
I have a grid laid out like so; +---------+---------+ | Image | Details |
I have a grid and I need to dynamically replace a control that resides
I have a grid that has multiple rows. I want to hide/show one of
I have a grid view control in my application. Please see the below code.
I have a grid in a XAML file in a WPF project. This MainGrid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.