on 07-27-2005 11:04 AM
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());
}
}
Hmz... Found something in the UI API:
<i>We recommend using XML to add a form menu. This will allow your add-on to open multiple forms of the same type(with form menu) in parallel without getting exceptions on identical menu unique IDs. For more information, see the <FormMenu> element in Adding Forms with XML.</i>
Okey, so I try to load the code below into SBO, but I get the error <i>"System.Runtime.InteropServices.COMException (0xFFFFE4A8): Form - Invalid"</i>. Anybody any suggestions...?
Thnx
<?xml version="1.0" encoding="UTF-16"?>
<Application>
<forms>
<action type="update">
<form FormType="150" appformnumber="150">
<FormMenu type="add">
<menu UniqueId="LOCTRANS" Enabled="0" Position="8" String="V&oorraadboekingslijst op locatie" Type="1"/>
</FormMenu>
</form>
</action>
</forms>
</Application>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have tried to reproduce your problem and I have succeeded.
I open my form once with a context menu.
I open my form a second time with a different UID but the same menu => Exception Menu already exists.
If I open my form using Xml the first time (I have saved my complete form in Xml and I load everything at once) then the context menu is Ok.
If I open my form a second time (with a different UID) then I have no error message but I have no context menu added to the form.
I think you should create a Customer Message to report this problem to the support. Maybe they can give you the right way to do it.
Please let as know if you find something interesting!
Regards
Trinidad.
Hello,
The following XML works for me
<?xml version="1.0" encoding="UTF-16"?>
<Application>
<forms>
<action type="add">
<form AutoManaged="0" BorderStyle="4" FormType="60006" ObjectType="-1" SupportedModes="15" appformnumber="60006" client_height="175" client_width="194" color="1" default_button="" height="200" left="300" mode="1" pane="0" title="Example1" top="150" type="4" uid="Example0" visible="1" width="200">
<datasources>
.....
</datasources>
<Menus/>
<items>
.....
</items>
<FormMenu>
<Menus>
<action type="add">
<Menu Checked="0" Enabled="1" FatherUID="5888" Image="" Position="0" String="Hello" Type="1" UniqueID="hello"/>
<Menu Checked="0" Enabled="1" FatherUID="5888" Image="" Position="0" String="World" Type="1" UniqueID="world"/>
</action>
</Menus>
</FormMenu>
<DataBrowser/>
</form>
</action>
</forms>
</Application>
Talk later,
Cormac
User | Count |
---|---|
99 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.