3 Replies Latest reply on Apr 19, 2017 2:21 AM by Christoph Engelhardt

    Adding several buttons with AddCommandItem2

    Christoph Engelhardt

      Hi there,

      I use the following code in an addin to create a command manager group and I would like to add three buttons with AddCommandItem2:

       

      public void AddCommandMgr()

              {

                  ICommandGroup cmdGroup;

       

                  Assembly thisAssembly;

                  thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType());

       

                  cmdGroup = iCmdMgr.CreateCommandGroup(1, "Tools", " ??? ", " !!! ", 3);

       

                  cmdGroup.AddCommandItem2("Function 1", 0, "Number 1", "first", 0, "function1", null, 0, (int)(swCommandItemType_e.swMenuItem |                          swCommandItemType_e.swToolbarItem));

                  cmdGroup.AddCommandItem2("Function 2", -1, "Number 2", "second", 0, "function2", null, 0, (int)(swCommandItemType_e.swMenuItem |                                                            swCommandItemType_e.swToolbarItem));

                  cmdGroup.AddCommandItem2("Function 3", -1, "Number 3", "third", 0, "function3", null, 0, (int)(swCommandItemType_e.swMenuItem |                          swCommandItemType_e.swToolbarItem));

       

                  cmdGroup.HasToolbar = true;

                  cmdGroup.HasMenu = true;

                  cmdGroup.Activate();

              }

       

      Unfortunately, the toolbar shows one button for function 3 (first screenshot) instead of three buttons for function 1, 2 and 3. The menu shows three times function 3 instead of function 1, 2, and 3 (second screenshot).

       

       

      Am I missing something?

       

      Thanks in advance for your comments!

        • Re: Adding several buttons with AddCommandItem2
          roberto gennari

          Hi Christoph,

          change the red word in your code and test it.

           

          public void AddCommandMgr()

                  {

                      ICommandGroup cmdGroup;

           

                      Assembly thisAssembly;

                      thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType());

           

                      cmdGroup = iCmdMgr.CreateCommandGroup(1, "Tools", " ??? ", " !!! ", 3);

           

                      cmdGroup.AddCommandItem2("Function 1",-1, "Number 1", "first", 0, "function1", null, 0, (int)(swCommandItemType_e.swMenuItem |                          swCommandItemType_e.swToolbarItem));

                      cmdGroup.AddCommandItem2("Function 2", -1, "Number 2", "second", 1, "function2", null, 1, (int)(swCommandItemType_e.swMenuItem |                                                            swCommandItemType_e.swToolbarItem));

                      cmdGroup.AddCommandItem2("Function 3", -1, "Number 3", "third", 2, "function3", null, 2, (int)(swCommandItemType_e.swMenuItem |                          swCommandItemType_e.swToolbarItem));

           

                      cmdGroup.HasToolbar = true;

                      cmdGroup.HasMenu = true;

                      cmdGroup.Activate();

                  }