esdTeamsters
asked on
Reference to a non-shared member requires an object reference
Hi all,
I have an application with two forms, in which the following occurrs:
1. MainForm opens ChildForm.
2. Before ChildForm closes it should call to a sub in MainForm.
3. This sub should take parameters passed from ChildForm and populate a TreeView within MainForm.
This worked fine when the project was configured as a Windows Application. However, it has become necessary to change this to a Class Library. After doing so, the call to the sub in MainForm errors out with "Reference to a non-shared member requires an object reference". If I change the sub to Public Shared, it cannot manipulate the control it is supposed to populate. I tried creating an object reference from the ChildForm as it suggests but when I step through the code, it seems to work but nothing populates in the TreeView.
Any help will be extremely helpful. Thanks!
Public Class MainForm
...
' Populate the TreeView with the data from ChildForm
Private Sub GetInfoFromChildForm(ByVal Info as string)
...
End Sub
...
End Class
Public Class ChildForm
...
' Pass the info to MainForm
Private Sub PassInfo()
' Call the sub in MainForm that populates the MainForm TreeView
MainForm.GetInfoFromChildF orm(InfoTo Pass)
End Sub
...
End Class
I have an application with two forms, in which the following occurrs:
1. MainForm opens ChildForm.
2. Before ChildForm closes it should call to a sub in MainForm.
3. This sub should take parameters passed from ChildForm and populate a TreeView within MainForm.
This worked fine when the project was configured as a Windows Application. However, it has become necessary to change this to a Class Library. After doing so, the call to the sub in MainForm errors out with "Reference to a non-shared member requires an object reference". If I change the sub to Public Shared, it cannot manipulate the control it is supposed to populate. I tried creating an object reference from the ChildForm as it suggests but when I step through the code, it seems to work but nothing populates in the TreeView.
Any help will be extremely helpful. Thanks!
Public Class MainForm
...
' Populate the TreeView with the data from ChildForm
Private Sub GetInfoFromChildForm(ByVal
...
End Sub
...
End Class
Public Class ChildForm
...
' Pass the info to MainForm
Private Sub PassInfo()
' Call the sub in MainForm that populates the MainForm TreeView
MainForm.GetInfoFromChildF
End Sub
...
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My mistake, I got it to work. Thanks for the quick response!!
dim childForm as ChildForm
childForm = new ChildForm()
childForm.mainForm = Me ' did you add this line?
Last line sets reference to main form in child form.
public mainForm as MainForm ' no need in New
If you don't khow where to apply this code, post code fragment where you create and show child form from main form.
childForm = new ChildForm()
childForm.mainForm = Me ' did you add this line?
Last line sets reference to main form in child form.
public mainForm as MainForm ' no need in New
If you don't khow where to apply this code, post code fragment where you create and show child form from main form.
Thats not it. What I mean is if I put a button on form1 (lets say) and type in form2.Button2_Click after I put in Form2. I should get a list of options like controls on Form2. I do not see them and if I just type them in I get the error.
Sorry I posted to the wrong question.
ASKER
public mainForm as MainForm
to
public mainForm as New MainForm
...and it doesn't error out on me, but doesn't populate the control either.