Re: Calling an event in a different namespace
-
Ok so I posted this a while ago and I need to reiterate the question: In panelMasterlist I have a delete event:
public void contextDeleteMasterList_Click(object sender, EventArgs e)
{
// Delete Rule: Inventory Item in all Restaurants cannot be in the MasterlistfrmGenericProgress F = sender as frmGenericProgress; List<MasterListItem> deletedObjects = new List<MasterListItem>(); .............}
It populates a list then validates it... etc. In frmMain I have a button event from a 3rd component that when triggered need to do the exact same thing done in contextDeleteMasterList_Click.
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{So I made the contextDeleteMasterList_Click public, and in the buttonDeleteMasterlist_Activate tried calling
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click();
}got Error 1 No overload for method 'contextDeleteMasterList_Click' takes '0' arguments tried:
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click(sender, e);
}got Error 1 An object reference is required for the nonstatic field, method, or property 'Freepour.Studio.Forms.Panels.panelMasterlist.contextDeleteMasterList_Click(object, System.EventArgs) Any help is greatly appreciated
-
Ok so I posted this a while ago and I need to reiterate the question: In panelMasterlist I have a delete event:
public void contextDeleteMasterList_Click(object sender, EventArgs e)
{
// Delete Rule: Inventory Item in all Restaurants cannot be in the MasterlistfrmGenericProgress F = sender as frmGenericProgress; List<MasterListItem> deletedObjects = new List<MasterListItem>(); .............}
It populates a list then validates it... etc. In frmMain I have a button event from a 3rd component that when triggered need to do the exact same thing done in contextDeleteMasterList_Click.
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{So I made the contextDeleteMasterList_Click public, and in the buttonDeleteMasterlist_Activate tried calling
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click();
}got Error 1 No overload for method 'contextDeleteMasterList_Click' takes '0' arguments tried:
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click(sender, e);
}got Error 1 An object reference is required for the nonstatic field, method, or property 'Freepour.Studio.Forms.Panels.panelMasterlist.contextDeleteMasterList_Click(object, System.EventArgs) Any help is greatly appreciated
try:
panelMasterlist.contextDeleteMasterList\_Click(null, null);
[Added] My bad. Wasn't reading carefully. You need to either create a new instance of PanelMasterList and then call the method such as
....MasterPanelList mpl = new MasterPanleList();
mpl.contextDeleteMasterList_Click(null, null);or create and use a delegate to call that method. Or make the method/event handler static. But this really is a bad practice. [/Added]
-
Ok so I posted this a while ago and I need to reiterate the question: In panelMasterlist I have a delete event:
public void contextDeleteMasterList_Click(object sender, EventArgs e)
{
// Delete Rule: Inventory Item in all Restaurants cannot be in the MasterlistfrmGenericProgress F = sender as frmGenericProgress; List<MasterListItem> deletedObjects = new List<MasterListItem>(); .............}
It populates a list then validates it... etc. In frmMain I have a button event from a 3rd component that when triggered need to do the exact same thing done in contextDeleteMasterList_Click.
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{So I made the contextDeleteMasterList_Click public, and in the buttonDeleteMasterlist_Activate tried calling
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click();
}got Error 1 No overload for method 'contextDeleteMasterList_Click' takes '0' arguments tried:
private void buttonDeleteMasterlist_Activate(object sender, EventArgs e)
{
panelMasterlist.contextDeleteMasterList_Click(sender, e);
}got Error 1 An object reference is required for the nonstatic field, method, or property 'Freepour.Studio.Forms.Panels.panelMasterlist.contextDeleteMasterList_Click(object, System.EventArgs) Any help is greatly appreciated
The first error tells you you try to use a method with a wrong signature. The second error tells you the method you're trying to use is not static (i.e. you can't access it from its class, you have to use an instance of the panelMasterList to call the method). So, if your main form holds an instance of panelMasterList, use the variable referencing this instance to call the method :
myPanelMasterList.contextDeleteMasterList_Click(sender, e);
Or make the method static in the panelMasterList Class :
public static void contextDeleteMasterList_Click(object sender, EventArgs e) {...}
But, depending on how you organized your application, there could be some more issues. This is only what I can think of regarding the informations you provided. Kind regards.
-
try:
panelMasterlist.contextDeleteMasterList\_Click(null, null);
[Added] My bad. Wasn't reading carefully. You need to either create a new instance of PanelMasterList and then call the method such as
....MasterPanelList mpl = new MasterPanleList();
mpl.contextDeleteMasterList_Click(null, null);or create and use a delegate to call that method. Or make the method/event handler static. But this really is a bad practice. [/Added]