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

IToolbarControl.AddItem 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.AddItem Method
ArcGIS Developer Help

IToolbarControl.AddItem Method

Adds an item to the ToolbarControl.

[Visual Basic .NET]
Public Function AddItem ( _
    ByVal item As Object, _
    [ByVal SubType As Integer], _
    [ByVal index As Integer], _
    [ByVal beginGroup As Boolean], _
    [ByVal GroupSpacing As Integer], _
    [ByVal Style As esriCommandStyles] _
) As Integer
public int AddItem (
    object item,
    int SubType,
    int index,
    bool beginGroup,
    int GroupSpacing,
    esriCommandStyles Style
  VARIANT item,
  long SubType,
  long index,
  VARIANT_BOOL beginGroup,
  long GroupSpacing,
  esriCommandStyles Style
item [in]

item is a parameter of type VARIANT SubType [in, optional, defaultvalue()]
SubType is a parameter of type long index [in, optional, defaultvalue()]
index is a parameter of type long beginGroup [in, optional, defaultvalue()]
beginGroup 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 command and creates a new item that is added to the ToolbarControl with its Command or Menu or Palette set, and returns the index of the first item added. Specifiy the command, menu or palette as either a IUid, ProgID, ICommand, IMenuDef, IToolbarMenu, IPaletteDef or IToolbarPalette. AddItem supports the following objects: ICommand, IMenuDef, IToolbarMenu, ICommandSubType, ITool, IToolControlIPaletteDef and IToolbarPalette . Visually items are represented on the ToolbarControl as buttons, tools, menus, text boxes and combo boxes. 

Supply a subType when passing an ICommandSubType. If no subType is supplied and the command is passed as a IUid or ProgID then ICommandSubType::GetCount determines the number of Item's to be added to the ToolbarControl. A subType must be supplied when passing an ICommandSubType as an ICommand, or the method will fail. By default subType is 0.

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

beginGroup determines whether a separator will appear before the item. By default beginGroup is False.

GroupSpacing determines the width in pixels of the separator.

Style determines the sytle of the item. By default Style is set to esriCommandStyleIconOnly.

Errors Returned

1023 800a03ff: The specified index is out of range
1034: The supplied command is invalid
1035 800a040b The subtype specified for the command (possibly in a UID object) is invalid or out of range
1038 800a040e: Tool control is already on a ToolbarControl, only one instance of a tool control can be added
1068: A subtype must be specified when adding an ICommandSubType object
1074 800a0432: The specified multi-item object can only be added to a ToolbarMenu


AddItem checks to see if the supplied command already exists in the CommandPool used by the ToolbarControl. If the command does not already exist, it is created and added to the CommandPool with a ICommandPool::UsageCount of 1, and is set as the IToolbarItem::Command. If the command already exists in the CommandPool, then the command instance is reused, its ICommandPool::UsageCount is incremented by 1 and the command is set as the IToolbarItem::Command. The ICommand::OnCreate method will be called the first time a command is added to the CommandPool.

Where possible always supply commands, menus and palettes as either Uid objects or ProgID's. Only supply commands as ICommand, IMenuDef or IPaletteDef  objects when a IUid or ProgID does not exist, and the class is compiled as part of the same project using the ToolbarControl. Passing a command menu or palette as an ICommand, IMenuDef or IPaletteDef object has the following limitation: Multiple instances of the same command can be added to the CommandPool, and each IToolbarItem::Command will point to a different command object. For example, setting a command implementing the ITool interface to be the CurrentTool would result in only one item appearing visually pressed on the on the ToolbarControl.

//Adding a command by UID
UID uID = new UIDClass();
uID.Value = "esriControls.ControlsMapFullExtentCommand";

//Adding a command by ProgID
string progID = "esriControls.ControlsMapFullExtentCommand";

//Adding a command by ICommand
ICommand command = new ControlsMapFullExtentCommandClass();
[Visual Basic .NET]
'Adding a command by UID
Dim pUid As New UIDClass
pUid.Value = "esriControls.ControlsMapFullExtentCommand"

'Adding a command by ProgID
Dim sProgID As String
sProgID = "esriControls.ControlsMapFullExtentCommand"

'Adding a command by ICommand
Dim pCommand As ICommand
pCommand = New ControlsMapFullExtentCommandClass

See Also

IToolbarControl Interface