Showing results for 
Search instead for 
Do you mean 

Add custom toolbar causes Exception

Tuned Listener
Posts: 29
Country: United States

Add custom toolbar causes Exception

I am attempting to create a toolbar.  I have successfully added a Menu item but the toolbar work isn't working.  I get the Exception: Object Reference not set to an instance of an object - at ControlCollection.Add (see below).


Code is:


 private const string CUSTOM_TOOLBAR_TEXT = "Toolbar";

private const string CUSTOM_TOOLBAR_URN = "Act.MenuToolbar.Button";

 CommandBar myBar = null;



MessageBox.Show("Initiate load of new menu item"); if (application.Explorer.CommandBarCollection[CUSTOM_TOOLBAR_TEXT] == null)


myBar = application.Explorer.CommandBarCollection.Add(CUSTOM_TOOLBAR_TEXT, CommandBarType.Toolbar);application.Explorer.CommandBarCollection.Add(myBar,


myBar.IsVisible = true;myBar.CustomBar =




System.Drawing.Icon btnIcon = application.Icon;

Act.UI.Core.CommandBarButton button = new CommandBarButton("Test1", "This is a test", btnClick_OnClick, CUSTOM_TOOLBAR_URN, btnIcon,CommandBarControl.ItemDisplayStyle.ImageAndText, false);button.ControlType =


button.ControlAlignment = CommandBarControl.ItemAlignment.Near;

//button.Icon = btnIcon;



catch (Exception e)


MessageBox.Show("A problem occurred loading the menu item: " + e.Message);



At the ControlCollection.Add, I have checked that both "button" and "myBar" do exist and are not null.  Obviously, something is either not being set up in one of these two objects but I can not find any documentation that would lead me to a solution.  I went back through what examples are available and I think I have followed them.


Any and all help appreciated!




Tom Gueth
Knowledge Resource
Binary Star Technology, Inc