Adding custom menu item

Emanuele Croci

Dear all,


is it possible via SAP DI API to add a new menu item at first level (same level of "Administration", "Sales", "Purchase", ...)?


 


Please, can someone give me an example of sourcecode to add it?


 


Best regards


 


    Emanuele


 


martinsalo

You could use code like this:



public void CreateMenu(SwissAddonFramework.UI.Components.MenuItem menuItemConfiguration) {

     MenuItem SapModules = MenuItem.GetFromUID("43520"); // Menu: Module
     MenuItem MyModule = MenuItem.CreateNew("mnu_MyModul");
     MyModule.Type = MenuItem.MenuType.Popup;
     MyModule.Value = "New Menu";
     SapModules.SubMenus.AddMenuItem(MyModule);

     CreateSubMenu(MyModule, "mnuSub1", "Hello World", EventHandlerMenuClick);

     SapModules.Load();
}

public void CreateSubMenu(MenuItem ModulMenu, string MenuName, string MenuCaption, SwissAddonFramework.UI.EventHandling.MenuEvents.MenuEventHandler EventHandler) {
    try {
        MenuItem SubMenu = null;
        SubMenu = MenuItem.CreateNew(MenuName);
        SubMenu.RemoveAllHandlers();

        SubMenu.Value = MenuCaption;
        ModulMenu.SubMenus.AddMenuItem(SubMenu);
        SubMenu.AddHandler_Click(EventHandlerMenuClick);
                
    } catch (Exception ex) {
        SwissAddonFramework.Messaging.StatusBar.WriteError(ex.ToString());
    }
}

private void EventHandlerMenuClick(SwissAddonFramework.UI.EventHandling.MenuEvents.MenuClick ev) {
SwissAddonFramework.Messaging.StatusBar.Write("Menu Click");
}

Emanuele Croci

Dear Martinsalo,


thank you very much for your help.


 


Please, can you give me the VB.Net version of this source-code?


I don't know how to implement the part


 


    SubMenu.AddHandler_Click(EventHandler)


 


 


Best regards


 


     Emanuele

martinsalo

I have corrected the C# code. The event handler name is not EventHandler, its EventHandlerMenuClick in this example.


Its several years ago I have programmed in VB.net. I forgot it. But I think the method calls are the same. You only have to re-implement the basic structure concepts like try/catch and variables definitions.


Emanuele Croci

Thank you very much.

0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post