Sometimes you might want to pass information that has been generated in one form, to another form for additional use. This is useful for forms that display a search tool, or a settings page among many other uses.
Let's say you want to pass a DataTable
between a form that is already open (MainForm) and a new form (NewForm):
In The MainForm:
Private Sub Open_New_Form()
Dim NewInstanceOfForm As New NewForm(DataTable1)
NewInstanceOfForm.ShowDialog()
End Sub
In The NewForm
Public Class NewForm
Dim NewDataTable as Datatable
Public Sub New(PassedDataTable As Datatable)
InitializeComponent()
NewDataTable= PassedDataTable
End Sub
End Class
Now when the NewForm is opened, it is passed DataTable1
from MainForm and stored as NewDataTable
in NewForm for use by that form.
This can be extremely useful when trying to pass large amounts of information between forms, especially when combining all of the information in to a single ArrayList
and passing the ArrayList
to the new form.