Delete Map Grids

Created:3/23/2001
Description:

You can use this sample's code to delete all of the map grids in the focus map.

How to use:
  1. Copy-paste this sample's code into a module in your Visual Basic Editor.
  2. Run the procedure. This will remove all map grids from the currently selected data frame.
Public Sub DeleteMapGrids()
  Dim pMxDoc As IMxDocument
  Dim pMap As IMap
  Dim pActiveView As IActiveView
  Dim pGraphicsContainer As IGraphicsContainer
  Dim pMapFrame As IMapFrame
  Dim pMapGrids As IMapGrids
  Dim pMapGrid As IMapGrid
  
  Set pMxDoc = ThisDocument
  Set pMap = pMxDoc.FocusMap
  Set pActiveView = pMxDoc.PageLayout
  Set pGraphicsContainer = pMxDoc.PageLayout
  Set pMapFrame = pGraphicsContainer.FindFrame(pMap)
  Set pMapGrids = pMapFrame
  
  Dim i As Long
  Dim count As Long
    
  ' Delete all mapgrids and refresh
  count = pMapGrids.MapGridCount
  For i = count - 1 To 0 Step -1
    'if you remove grid(0) first, then grid(1) becomes grid(0)
    Set pMapGrid = pMapGrids.MapGrid(i)
    pMapGrids.DeleteMapGrid pMapGrid
    Set pMapGrid = Nothing
  Next i
  pActiveView.PartialRefresh esriViewBackground, Nothing, Nothing
End Sub