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


IToolbarControl.AddItem Method (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference (Controls)  

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
[C#]
public int AddItem (
    object item,
    int SubType,
    int index,
    bool beginGroup,
    int GroupSpacing,
    esriCommandStyles Style
);
[C++]
HRESULT AddItem(
  VARIANT item,
  long SubType,
  long index,
  VARIANT_BOOL beginGroup,
  long GroupSpacing,
  esriCommandStyles Style
);
[C++]

Parameters 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.

Description

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

Remarks

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.

[C#]
//Adding a command by UID
UID uID=new UIDClass();
uID.Value="esriControls.ControlsMapFullExtentCommand";
axToolbarControl1.AddItem(uID,-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);

//Adding a command by ProgID
string progID="esriControls.ControlsMapFullExtentCommand";
axToolbarControl1.AddItem(progID,-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);

//Adding a command by ICommand
ICommand command=new ControlsMapFullExtentCommandClass();
axToolbarControl1.AddItem(command,-1,-1,false,0,esriCommandStyles.esriCommandStyleIconOnly);
[Visual Basic .NET]
'Adding a command by UID
Dim pUid As New UIDClass
pUid.Value="esriControls.ControlsMapFullExtentCommand"
AxToolbarControl1.AddItem(pUid)

'Adding a command by ProgID
Dim sProgID As String
sProgID="esriControls.ControlsMapFullExtentCommand"
AxToolbarControl1.AddItem(sProgID)

'Adding a command by ICommand
Dim pCommand As ICommand
pCommand=New ControlsMapFullExtentCommandClass
AxToolbarControl1.AddItem(pCommand)

See Also

IToolbarControl Interface

.NET Snippets

Add Ink Commands to ToolbarControl | Add Globe Commands to ToolbarControl | Add Map Commands to ToolbarControl | Add Schematics Commands to ToolbarControl