Nevron Forum

Problem adding multiple buttons to custom toolbar

https://www.nevron.com/Forum/Topic4035.aspx

By Eric Sweet - Monday, August 23, 2010

Hi,

I've used the code from the sample app to add custom menu items, overload the functionality of existing buttons and add a single toolbar and button without any problems, but I am having trouble with adding more than one button to a custom toolbar. I always end up with just one button, and no errors. Can you provide any assistance with the code from the sample app for adding multiple buttons?

Thanks
Eric
By Nevron Support - Tuesday, August 24, 2010

Hi Eric,

Here is the requested code sample that adds two custom menu items with hosted button:

NButton btn1 = new NButton();
btn1.Text =
"Button 1";

NControlHostCommand controlHost1 = new NControlHostCommand();
controlHost1.SetControl(btn1);

nDockingToolbar1.Commands.Add(controlHost1);

NButton btn2 = new NButton();
btn2.Text = "Button 2";

NControlHostCommand controlHost2 = new NControlHostCommand();
controlHost2.SetControl(btn2);

nDockingToolbar1.Commands.Add(controlHost2);

By Eric Sweet - Tuesday, August 24, 2010

Thanks, I'll try it shortly. Just to make sure though, this will work with the built in command bars manager used by the diagramming control? Because the code looks nothing like the code from the sample application for adding a button.

Thanks again,
Eric
By Nevron Support - Tuesday, August 24, 2010

Hi Eric,

The example code above applies for NCommandBarsManager control, not for NDiagramCommandBarsManager.

In the example application (I guess you mean CommandBars example) to add another NCustomDiagramButtonCommand you need to set its ID property with value equal to the Id of the previous command + 1. Also in the example there is a filed customCommandIds of type ArrayList. In Reset method you should add a int value equal to the new command Id.

This way you should be able to add another button command to the diagram command bars manager.

Please, let us know if you still have problem with this.

By Eric Sweet - Thursday, August 26, 2010

That did the trick. I changed the reset event to a for loop that increments the counter for each button added and it works. Thanks for the advice.

Eric