Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Re: Calling an event in a different namespace

Re: Calling an event in a different namespace

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roman_s
    wrote on last edited by
    #1

    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 Masterlist

            frmGenericProgress 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

    D O 2 Replies Last reply
    0
    • R roman_s

      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 Masterlist

              frmGenericProgress 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

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      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]

      R 1 Reply Last reply
      0
      • R roman_s

        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 Masterlist

                frmGenericProgress 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

        O Offline
        O Offline
        O Phil
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D Dan Mos

          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]

          R Offline
          R Offline
          roman_s
          wrote on last edited by
          #4

          Thank you first method worked!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups