I currently have about 5 forms in my application. I'm building a 6th form - frmSummary however, I'd like to be able to access it from all forms. in frmSummary I am planning to add a DataGridView, where I'll be displaying data related to that form. I'm thinking that I should either create a global variable such as
dim FrmName as String
Private Sub cmdSummary_Click(sender As Object, e As EventArgs) Handles cmdSummary.Click
Dim NewMDIChild As New frmClientEligibilityReferral()
frmName = "CustomerInfo" --since this will be comeing from frmCustomerInfo
NewMDIChild.MdiParent = MDIform1
Private Sub FrmSummary_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.MdiParent = MDIForm1
'Here I want to call a function to load the datagridView(with g_frmName)see below...
If there is only one frmSummary, you could make it a singleton.
In frmSummary, put the following code:
Private Shared _instance As frmSummary Private Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub Public Shared Function GetInstance() As frmSummary If _instance Is Nothing Then _instance = New frmSummary() End If Return _instance End Function Public Sub PutDataInGrid(data As Object) Me.DataGridView1.' put data in it End Sub
And you would access it from other forms like this
Dim myFrmSummary = frmSummary.GetInstance() myFrmSummary.PutDataInGrid(myData)