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

  • Home
  • SEARCH
  • 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 6547579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:50:54+00:00 2026-05-25T11:50:54+00:00

I’ve a problem with my C# Code. At the moment I try to program

  • 0

I’ve a problem with my C# Code. At the moment I try to program a Windows Forms Application with more than one Window.
Now my problem:

At the first window I’ve a combobox with some values. When I click on a button, the second window opens and there it should be possible to add a value to this combobox on the first form.

The problem is that in the first window I´ve a LinkedList where my values are in.

Like this:

public LinkedList<String> sample = new LinkedList<String>();


hase.AddFirst("test");
combobox.Items.AddRange(sample.ToArray());

Now, in the second window the LinkedList isn’t available, even if I make it public.
What is the best way to solve this problem?

Hope you understand my problem…

Harald

  • 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-25T11:50:55+00:00Added an answer on May 25, 2026 at 11:50 am

    Without knowing exactly how to are trying to access the LinkedList, it’s hard to say why it isn’t working for you.

    Let’s go over what you have. You have a LinkedList, which is an instance variable on a form. Since this LinkedList is an instance variable, it is associated with the instance of the form.

    This example below, will not work because it tries to access it statically:

    public class MyForm : Form
    {
        public LinkedList<string> _list = new LinkedList<string>();
    }
    
    public class MySecondForm : Form
    {
        public void Window_Loaded(object sender, EventArgs e)
        {
            MyForm._list.AddFirst("This doesn't work");
            //WRONG! list is an instance variable we are trying to access statically.
        }
    }
    

    So, we can see this does not work. We have a few options to get this working. First off, one very bad solution would be to actually make list static. Don’t use this option. It’s opens the door for concurrency problems, possibly leaking strong references, etc. Generally, using statics (like a singleton) I would discourage for passing data around for these reasons. The Singleton Pattern has a time and a place, but I don’t think this is it since it can so easily be avoided.

    OK, since we got the bad solution out of the way, let’s look at a few possible good ones.

    Set the list on MySecondForm. You have a few options for this. The constructor, a property, or a method. For example:

    public class MyForm : Form
    {
        private LinkedList<string> _list = new LinkedList<string>();
    
        public void Button1_Click(object sender, EventArgs e)
        {
            var secondForm = new MySecondForm();
            secondForm.SetList(_list);
            secondForm.ShowDialog();
            MessageBox.Show(_list.First.Value);
        }
    }
    
    public class MySecondForm : Form
    {
        private LinkedList<string> _list;
    
        public void Window_Loaded(object sender, EventArgs e)
        {
            this._list.AddFirst("This will work");
        }
    
        public void SetList(LinkedList<string> list)
        {
            _list = list;
        }
    }
    

    This is one possible solution. The constructor is another possible solution as Billy suggested.

    Because LinkedList is a reference type, any changes you make to it on the instance of MySecondForm will be reflected on the linked list of MyForm.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

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.