Refreshing a datagrid on another form
I am trying to refresh a datagrid on one form from another. I found a code sample on this forum where I could click a button from a second form like this (Public Shared):
Form1
VB Code:
' This is form1
Public Shared Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Hello World")
End Sub
Private Sub Button2_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim xForm As New Form2
xForm.Show()
End Sub
Form2
VB Code:
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim zForm As New Form1
zForm.Button1_Click(Me, Nothing)
End Sub
Pushing the button on the second form causes the button on the first form to show the Hello World message.
Now when I try to do the same thing with a button that refresshes a datagrid I get this error: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
How do I overcome that?