List is lost when Form is not active

This is a discussion on List is lost when Form is not active within the C# Programming forums, part of the General Programming Boards category; Hello there I'm trying to make an editor with Visual C#, and storing the data in the Form in List<T> ...

  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
    Portugal
    Posts
    7,460
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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, 01: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, 04:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21