Results 1 to 9 of 9

Thread: After Form Load Event?

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    After Form Load Event?

    Is there a way to launch some code after the Form_Load method executes? I'm having some trouble in a MDI child. When I put the code I need to execute in the Form_Load, I get an OutOfMemoryException, but if I put this code under a button click in the child form, things work fine.

    Thanks,
    Mike

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    What about if you place the code into a Sub, which you call from the Form_Load?

    Also, you could call another event like

    VB Code:
    1. Call Event_Name(Nothing, Me) 'for args, sender

  3. #3

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Thanks, mendhak, problem solved. Placing the code in a method called from Form_Load does not work, generating the same exception. But calling a public method after Form.Show to execute the code works fine.

    Not sure why it works, but it works. Thanks!

    Mike

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    What exactly are you doing that's not working in the Form_Load?

    Maybe that'll give us a clue...

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Mike Hildner
    Thanks, mendhak, problem solved. Placing the code in a method called from Form_Load does not work, generating the same exception. But calling a public method after Form.Show to execute the code works fine.

    Not sure why it works, but it works. Thanks!

    Mike
    I agree with mendhak. I have no problem with calling from the load event of a child. It must be peculiar to what you are coding.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Populating a tree view with tables from a database. This is done through a web service. This is in C#, but should be interpretable to VB folks:

    PHP Code:
                PatriotWebService.PatriotClientWebService ws = new PatriotWebService.PatriotClientWebService();
                
    dsTables ws.GetUserTables();
                
    // There's only one table in this data set, get it,
                // and run through all the record in it, populating the
                // tree view.
                
    DataTableCollection dtc dsTables.Tables;
                
    DataTable dtUserTables dtc[0];
                foreach (
    DataRow row in dtUserTables.Rows)
                {
                    
    //tvTableList.SelectedNode = 0;
                    //tvTableList.Nodes.Add(row["name"].ToString());
                    
    tvTableList.SelectedNode.Nodes.Add(row["name"].ToString());
                }
                
    tvTableList.ExpandAll(); 
    Initially, I had the above code in Form_Load. I used this code in the MDI container:
    PHP Code:
                Tables t = new Tables(); // Tables is a Windows form
                
    t.MdiParent this;
                
    t.Show(); 
    When this code was in the constructor of the MDI parent, all went well. I moved it to execute when you click a button, and when that happened, I got an OutOfMemoryException.

  7. #7
    New Member
    Join Date
    Oct 2007
    Location
    UK-Devon
    Posts
    1

    Re: After Form Load Event?

    A useful event for doing things once after form load is complete is the form's Shown event.

  8. #8
    Junior Member
    Join Date
    Oct 2007
    Posts
    29

    Re: After Form Load Event?

    Probably an error because the controls you are trying to load haven't initialized yet ?

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: After Form Load Event?

    Quote Originally Posted by gplayer
    A useful event for doing things once after form load is complete is the form's Shown event.
    Given that this thread was created in 2004, before .NET 2.0 was released, Shown wasn't an option. It certainly would be nowadays, but back then we had to use the Activated event with a Boolean variable to indicate whether it's the first time or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width