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 3282238
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:54:20+00:00 2026-05-17T19:54:20+00:00

Please help! I don’t know if maybe this is too simple but I can’t

  • 0

Please help! I don’t know if maybe this is too simple but I can’t get it right and can’t seem to find the right answer on other posts. I am relatively new to C# and I program for hobby only, this is my first post.

I have this method CreateMap() inside a class Met where I have all my methods. It creates an array of dynamic custom controls (stockBox[]) and adds them to a table layout panel (boxContainer) which is inside Form. This method runs when the application opens. I get everything to work fine, THE ISSUE is that I want to access the stockBox controls from another method inside the same class I can’t see stockBox with IntelliSense and it says it doesn’t exist!

public static class Met
{
    public static StockBox[] CreateMap(string[] stock, TableLayoutPanel boxContainer)
    {
        StockBox[] stockBox = new StockBox[Var.stockCount + 1];

        for (int i = 1; i <= Var.stockCount; i++)
        {
            stockBox[i] = new StockBox();
            stockBox[i].StockText = stock[i];
            boxContainer.Controls.Add(stockBox[i]);
        }

        return stockBox;
    }
}

Can’t place StockBox[] stockBox = new StockBox[Var.stockCount + 1] outside the method because then Var.stockCount is 0 and it will create an array with only one object.

Any ideas? What do you think I can do? Thanks in advance.

  • 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-17T19:54:20+00:00Added an answer on May 17, 2026 at 7:54 pm

    Your stockBox is currently n variable in CreateMap(). stockBox will be disposed when the method ends (out of scope). Therefore, you need to move the stockBox to class level as follow:

    public static class Met
    {
        static StockBox[] stockBox = null;
        public static StockBox[] CreateMap(string[] stock, TableLayoutPanel boxContainer)
        {
            stockBox = new StockBox[Var.stockCount + 1];
    
            for (int i = 1; i <= Var.stockCount; i++)
            {
                stockBox[i] = new StockBox();
                stockBox[i].StockText = stock[i];
                boxContainer.Controls.Add(stockBox[i]);
            }
    
            return stockBox;
        }
    
        public static AccessStockBox()
        {
            if (stockBox != null)
            {
                //you should be able to access stockbox here
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always get a Resources$NotFoundException but i don't know why. Please help Code: @Override
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know C++ very well especially the IO part. Can anyone please help
I don't know of the default server name. Can you please help me because
Please help me understand why this isn't working. I don't know if there is
I don't know quite how to phrase this so please help me with the
I don't know how can i validate the recaptcha thing via jQuery. Please help.
Please help me, I don't know what can be wrong with the following code:
I really don't get why this isn't working, so please help. I'm trying to
Can someone please help me to read/understand this deadlock graph? I don't understand why

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.