Skip to Content
0
Former Member
Jul 27, 2005 at 10:04 AM

Context menu trouble

51 Views

Hi there...

I've added a context menu item (thisForm.Menus.AddEx()) to the Item Master data form. The only problem is, this form can be opened more then once, and the context menu isn't visible in all instances, just the one I've it added to. That makes sense... 😊

But if I try to add the context menu item to the second instance, it trows a exception: "a menuitem with the same Unique ID already exists". The stupid thing: I check before I add if the menu item exists, and it says no, but if I try to add it: error... :S

I already checked if it existed in Application.Menus, but it does not exist there, it does not exist in ActiveForm.Menus, but if I try to add it it goes wrong...

Anybody any suggestions...?

<b>Code (C#)</b>

/// <summary>
/// This function adds a menuoption to the contextmenu of a specified form
/// </summary>
/// <param name="AFrm">The form</param>
/// <param name="AUid">The unique id of the menuitem</param>
/// <param name="ACaption">The caption of the menuitem</param>
/// <param name="APosition">The position, use -1 for none</param>
protected void AddContextMenuItem(SAPbouiCOM.Form AFrm, string AUid, string ACaption, int APosition)
{
  try
  {
    // Does this menu already exist?
    if(!AFrm.Menu.Exists(AUid))
    {
      // Create a menuparameter object
      SAPbouiCOM.MenuCreationParams MCP = (SAPbouiCOM.MenuCreationParams)SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams);

      // Set the required parameters
      MCP.Type = SAPbouiCOM.BoMenuType.mt_STRING;
      MCP.UniqueID = AUid;
      MCP.String = ACaption;

      // Set the position?
      if(APosition >= 0)
        MCP.Position = APosition;

      // Add the menu
      AFrm.Menu.AddEx(MCP);
    }
  }
  catch(Exception e)
  {
    // Exception handling
    Debug.WriteLine(e.ToString());
  }
}