Type | Description | |||
Index as Variant | A long expression that indicates the index of item in the collection, a string expression that indicates the item's caption. | |||
Item | An Item object being searched. |
Use the ItemByIndex property to access an Item object by its caption. Use the Count property to specify the number of items in the sub menu. Use the Item property to access an item by its identifier.
The following VB sample enumerates the items in a sub menu:
With ExMenu1(10).SubMenu Dim i As Long For i = 0 To .Count - 1 Debug.Print .ItemByIndex(i).Caption Next End With
The following VB sample recursively enumerates all items in the menu:
Private Sub scan(ByVal e As EXMENULibCtl.Menu) If Not (e Is Nothing) Then Dim i As EXMENULibCtl.Item For Each i In e Debug.Print i.Caption scan i.SubMenu Next End If End Sub
Or an alternative function without using for each statement will be:
Private Sub scan(ByVal e As EXMENULibCtl.Menu) If Not (e Is Nothing) Then Dim j As Long For j = 0 To e.Count - 1 Debug.Print e.ItemByIndex(j).Caption scan e.ItemByIndex(j).SubMenu Next End If End Sub
The following C++ sample enumerates the items in a sub menu:
CMenu1 subMenu = m_menu.GetItem( COleVariant( long(10) ) ).GetSubMenu(); for ( long i = 0; i < subMenu.GetCount(); i++ ) { CItem item = subMenu.GetItemByIndex( COleVariant( i ) ); OutputDebugString( item.GetCaption() ); }
The following VB.NET sample enumerates the items in a sub menu:
With AxExMenu1(10).SubMenu Dim i As Long For i = 0 To .Count - 1 Debug.WriteLine(.ItemByIndex(i).Caption()) Next End With
The following C# sample enumerates the items in a sub menu:
EXMENULib.Menu subMenu = axExMenu1[10].SubMenu; for (int i = 0; i < subMenu.Count; i++) { EXMENULib.item item = subMenu.get_ItemByIndex(i); System.Diagnostics.Debug.WriteLine(item.Caption); }
The following VFP sample enumerates the items in a sub menu:
With thisform.ExMenu1.Item(10).SubMenu local i For i = 0 To .Count - 1 wait window nowait .ItemByIndex(i).Caption Next EndWith