ICommandBar vs. IToolBarDef

2302
3
01-31-2013 12:48 PM
GhassanKarwchan
New Contributor III
I am migrating .NET, C# code for custom extension from version 9.3 to 10.1.
The code is creating many toolbars on the fly and add commands to them.

The code snippets for creating one toolbar is like follows:

    ICommandBars bars = m_application.Document.CommandBars;
    ICommandBar newBar = bars.Create("my new toolbar",  esriCmdBarType.esriCmdBarTypeToolbar);
    UID uid = new UIDClass();
    uid.Value = "{E1F29C6B-4E6B-11D2-AE2C-080009EC732A}";
    object index = 0;
    newBar.Add(uid, ref index);
    newBar.Dock(dockstyle, referencetoolbar);


so the above code works fine for 9.3
But when I recompile it on 10.1 , it produce an empty toolbar that has nothing.
I investigate, and found out that the command "Dock" is corrupting the toolbar.

So, without Dock, the toolbar is created properly

I am reading on ArcObjects, and the documentation of ICommandBars.Create, says that this will create VBA toolbar, and if you are using non VBA platform, then use IToolBarDef instead.

So, is this command (ICommandBars.Create) is not supported with 10.1 and .NET?
0 Kudos
3 Replies
GhassanKarwchan
New Contributor III
I don't understand how no body at ESRI can answer my question.
And the support at ESRI Canada sucks
If you don't know how to make a functional software then don't do it .

I will repeat my question because it is so simple.

I have this code that create toolbar on the fly

ICommandBars bars = m_application.Document.CommandBars;
ICommandBar newBar = bars.Create("my new toolbar", esriCmdBarType.esriCmdBarTypeToolbar);
newBar.Add("{.....}");
newBar.Dock(dockstyle, referencetoolbar);

The code works fine on 9.3,
But on 10.1 , the dock statement at the end is causing the toolbar to be empty.
Without the dock statement, the toolbar is created properly

Any idea?
Don't tell me that no one at ESRI can answer that.
Seriously
0 Kudos
by Anonymous User
Not applicable
The following code works for me in 10.1 as a C# add-in button.

    protected override void OnClick()
    {
      ICommandBars bars = ArcMap.Application.Document.CommandBars;
      ICommandBar newBar = bars.Create("my new toolbar", esriCmdBarType.esriCmdBarTypeToolbar);
      UID uid = new UIDClass();
      uid.Value = "{E1F29C6B-4E6B-11D2-AE2C-080009EC732A}";
      object index = 0;
      newBar.Add(uid, ref index);

      //find the standard toolbar and bang it on the end
      UID barID = new UIDClass();
      barID.Value = "esriArcMapUI.StandardToolBar";
      ICommandBar stb = bars.Find(barID, false, false) as ICommandBar;
      newBar.Dock(esriDockFlags.esriDockRight,stb);
    }
0 Kudos
GhassanKarwchan
New Contributor III
Thanks

I reviewed the code.
Actually the order of the code is important, which is weird

If I put the Dock statement before adding command buttons to the toolbar, it empty the toolbar for some reason.
But I moved the dock after, and it worked fine
And the funny thing that the 9.3 works fine with Dock before adding items.

something stupid going on.
0 Kudos