Thread: List is lost when Form is not active

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    List is lost when Form is not active

    Hello there

    I'm trying to make an editor with Visual C#, and storing the data in the Form in List<T> variables. Problem is, when I change the active window while the editor is running, or I open up in the editor a new Form, the data in my Lists is lost. What am I doing wrong?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    The list is being declared as private. Do not forget a Form is a class and by default any objects defined within default to private. If you wish for the list to be accessible, either:

    - Define it as public. Ugly. Should be avoided.
    - Pass it to the new form by defining a new constructor that accepts a List<T> as one of its arguments. You then call the new form with this constructor. Not very elegant on most circumstances, unless the constructor serves more purposes than simply avoiding the previous solution.
    - Define the List<T> object as a property of the main form, instead of a member. Elegant.

    There's also the possibility of using delegates. But I don't think you want to go there just yet.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM