ArcObjects Library Reference (Controls)  

IToolbarMenu.GetItem Method

Returns the item at the specified index from the ToolbarMenu.

[Visual Basic .NET]
Public Function GetItem ( _
    ByVal index As Integer _
) As IToolbarItem
[C#]
public IToolbarItem GetItem (
    int index
);
[C++]
HRESULT GetItem(
  long index,
  IToolbarItem** item
);
[C++]

Parameters

index [in]   index is a parameter of type long item [out, retval]

  item is a parameter of type IToolbarItem

Product Availability

Available with ArcGIS Engine.

Description

The property is used to access a particular item on the ToolbarMenu. The item at the top of the menu has an index of 0.

Errors Returned

1023 800A03FF: The specified index is out of range

Remarks

To loop through a ToolbarMenus item collection use the GetItem method in conjunction with the Count property.

[C#]
//Get a toolbar item
IToolbarItem toolbarItem = axToolbarControl1.GetItem(0);
//Get a the menu from the item  
IToolbarMenu toolbarMenu = toolbarItem.Menu;
if (toolbarMenu == null) return; 

toolbarItem = toolbarMenu.GetItem(0);                       //First Item
toolbarItem = toolbarMenu.GetItem(1);                       //Second Item
toolbarItem = toolbarMenu.GetItem(toolbarMenu.Count - 1);   //Last Item 


for (int i=0; i<=toolbarMenu.Count - 1;i++)
{
	IToolbarItem toolbarItem = toolbarItem.GetItem(i); 
	//Do something.. 
}
[Visual Basic .NET]
'Get  a toolbar item
Dim pToolbarItem As IToolbarItem
pToolbarItem = AxToolbarControl1.GetItem(0)
'Get a the menu from the item  
Dim pToolbarMenu As IToolbarMenu
pToolbarMenu = pToolbarItem.Menu
If pToolbarMenu Is Nothing Then Exit Sub

pToolbarItem = pToolbarMenu.GetItem(0)                            'First Item
pToolbarItem = pToolbarMenu.GetItem(1)                            'Second Item
pToolbarItem = pToolbarMenu.GetItem(pToolbarMenu.Count - 1)       'Last Item 

Dim i As Long
For i = 0 To pToolbarMenu.Count - 1
	pToolbarItem = pToolbarMenu.GetItem(i)
	'Do something..  
Next i

See Also

IToolbarMenu Interface