GefContextMenuItems.Count (read-only property)

Gets the number of objects in the collection.
Syntax: long = object.Count
Description:

Example:

Sub OnPreContextMenu(oContextMenu As GefContextMenu)
  ' Remove all native and point target menu items
  Dim cnt As Long
  
  cnt = oContextMenu.MenuItems.Count
  
  Dim types() As Long
  
  ReDim types(0 To cnt)
  Dim oContextMenuItem As GefContextMenuItem
  Dim oMenuItems As GefContextMenuItems
  
  Set oMenuItems = oContextMenu.MenuItems
  Dim index As Long
  index = 0
  For Each oContextMenuItem in oMenuItems
    types(index) = oContextMenuItem.Type
    index = index + 1
  Next oContextMenuItem
  Dim curType As Long
  Dim prevType As Long
  prevType = gefMenuItemTypeSeparator
  
  ' Go from back to front so that indexs are not
  ' invalidated as the menu is trasversed
  For index = cnt - 1 To 0 Step -1
    curType = types(index)
    If curType = gefMenuItemTypeNativeCommand Or _
      curType = gefMenuItemTypePointTarget Then
        oMenuItems.Remove index
    Else
      If curType = gefMenuItemTypeSeparator And prevType = gefMenuItemTypeSeparator Then
        oMenuItems.Remove index
      Else
        prevType = curType
      End If
    End If
  Next index
 
  'If the menu starts with a separator remove it
  If oMenuItems.Count > 0 Then
    If oMenuItems.Item(0).Type = gefMenuItemTypeSeparator Then
      oMenuItems.Remove 0
    End If
  End If
End Sub