Hello,

How do I reinitialise a form load event?

Example;

Form1 Loads data from a Db and has 3 buttons, each button represents showing data from a different table onto form2

When form2 is initialise for the first time i can use an onload event, but if i go back to page 1 and click a different button to show a different table i get the table from the origional as form2 does not use the onLoad event again.

To switch between forms i use

Class Form1
Public Shared whichtbl as string
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 '<Load Data etc>
End sub
    Private Sub btntbl1Data_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntbl1Data.Click
       whichtbl = "tbl1"
       Me.Hide()
       Form2.Show()
    End Sub
End class
Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 if whichtbl = "tbl1" then
 '<Load Data from button selected>
elseif  whichtbl = "tbl2" then
 '<Load Data from button selected>
elseif  whichtbl = "tbl3" then
 '<Load Data from button selected>
end if
End sub
    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
       Me.Hide()
       Form1.Show()
    End Sub
End Class

This is just some example code.

Thanks in advance for all your help

Recommended Answers

All 2 Replies

Use Form.Activated Event.

From MSDN article :
To activate a form at run time using code, call the Activate method. You can use this event for tasks such as updating the contents of the form based on changes made to the form's data when the form was not activated.

Use Form.Activated Event.

From MSDN article :
To activate a form at run time using code, call the Activate method. You can use this event for tasks such as updating the contents of the form based on changes made to the form's data when the form was not activated.

Brilliant Thanks mate

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.