GefContextMenuItems.Remove (method)

Removes the specified menu item from the context menu.
Syntax: object.Remove Index
Index As long - The numeric index. The numeric index ranges from 0 to Count-1.


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
      If curType = gefMenuItemTypeSeparator And prevType = gefMenuItemTypeSeparator Then
        oMenuItems.Remove index
        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