This document is archived and information here might be outdated.  Recommended version.

IToolbarControl.AddToolbarDef Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Controls > ESRI ArcGIS Controls > Interfaces > IT > IToolbarControl Interface > IToolbarControl.AddToolbarDef Method
ArcGIS Developer Help

IToolbarControl.AddToolbarDef Method

Appends the contents of the toolbar definition, specified by Guid or ToolbarDef, to the toolbar control.

[Visual Basic .NET]
Public Function AddToolbarDef ( _
    ByVal ToolbarDef As Object, _
    [ByVal startIndex As Integer], _
    [ByVal Group As Boolean], _
    [ByVal GroupSpacing As Integer], _
    [ByVal Style As esriCommandStyles] _
) As Integer
public int AddToolbarDef (
    object ToolbarDef,
    int startIndex,
    bool Group,
    int GroupSpacing,
    esriCommandStyles Style
HRESULT AddToolbarDef(
  VARIANT ToolbarDef,
  long startIndex,
  long GroupSpacing,
  esriCommandStyles Style
ToolbarDef [in]

ToolbarDef is a parameter of type VARIANT startIndex [in, optional, defaultvalue()]
startIndex is a parameter of type long Group [in, optional, defaultvalue()]
Group is a parameter of type bool GroupSpacing [in, optional, defaultvalue()]
GroupSpacing is a parameter of type long Style [in, optional, defaultvalue()]
Style is a parameter of type esriCommandStyles

Product Availability

Available with ArcGIS Engine.


Takes the specified toolbar definition and for each command specified an item is created and added to the ToolbarControl with an associated IToolbarItem::Command set. Specifiy the toolbar definition as either a IUid, ProgID, or IToolBarDef .

startIndex determines the position on the ToolbarControl each item will be added to. By default this is -1 and represents the end of the ToolbarControl.

Group determines whether separators will appear before the first and after the last item defined by the IToolBarDef . By default Group is False. Note this will override any IItemDef::Group property set in the IToolBarDef.

GroupSpacing determines the width of any separators, and applies to all item's defined by the IToolBarDef .

Style applies to all item's defined by the IToolBarDef. By default Style is set to esriCommandStyleIconOnly.

Where possible always supply toolbars as either Uid objects or ProgID's. Only supply toolbars as IToolBarDef objects when a IUid or ProgID does not exist, and the class is compiled as part of the same project using the ToolbarControl.

Errors Returned

1023 800A03FF: The specified index is out of range 

1040 800A0410: Errors occured adding commands from toolbardef

1042 800A0412: The supplied toolbar def object is invalid or contains zero commands 


For each command specified by the IToolBarDef, AddToolbarDef calls the AddItem method which checks to see if the supplied command already exists in the CommandPool. If the command does not already exist, it is added to the CommandPool with a ICommandPool::UsageCount of 1, and is set as the IToolbarItem::Command. If the command does already exist in the CommandPool its ICommandPool::UsageCount increments by 1 and the command is set as the IToolbarItem::Command. The ICommand::OnCreate method will only be called the first time a command is added to the CommandPool.

//Add a toolbardef by passing a UID
UID uID = new UIDClass();
uID.Value = "esriControls.ControlsMapNavigationToolbar";

//Add a toolbardef by passing a ProgID
string progID = "esriControls.ControlsMapNavigationToolbar";

//Add a toolbardef by passing an IToolbarDef 
IToolBarDef toolBarDef = new ControlsMapNavigationToolbarClass();
[Visual Basic .NET]
'Add a toolbardef by passing a UID
Dim pUid As New UIDClass
pUid.Value = "esriControls.ControlsMapNavigationToolbar"

'Add a toolbardef by passing a ProgID
Dim sProgID As String
sProgID = "esriControls.ControlsMapNavigationToolbar"

'Add a toolbardef by passing an IToolbarDef
Dim pToolBarDef As IToolBarDef
pToolBarDef = New ControlsMapNavigationToolbarClass

See Also

IToolbarControl Interface