Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an object that I need to add to a List before anything else happens, so I put List1.Add in Form_Load. The problem is other things are happening first, and of course crashing since the list is empty first. And I can't do List1.Add at the top of the form class outside of a function or sub.

How can I guarantee something will happen absolutely before anything else if not in Form_Load?
Posted
Comments
Sergey Alexandrovich Kryukov 16-Apr-14 22:44pm    
It depends on what do you mean by "anything else". For example, you don't want to call List1.Add before List1.Add is instantiated.
Okay, Solution 1 is the answer, only you should understand what happens. You can add your code in a constructor after InitializeComponent().

You should not leave auto-generated names like List1. You want all names to be semantic.

—SA

1 solution

Use the class constructor perhaps.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Apr-14 22:45pm    
More exactly, please see my comment to the question. Not a very correct question anyway...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900