Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a small application that allows the user to click on the map, and it will create 3 buffers (these are graphics using the IElement interface) at specified distances. What I want to do is if there are buffers on the map from the previous click, and the user clicks on the map to create another set of buffers, delete the oldest set of buffers (which are graphics) So in essence at anyone time there should only be 3 buffers on the map.

Has anyone got any ideas on the best way to do this?


share|improve this question
up vote 4 down vote accepted

You can delete graphics through the IGraphicsContainer interface, either DeleteElements or DeleteAllElements method. See sample code below.

Delete Graphics Refresh Active Snippet

Here is a Delete Graphic by Name VBA sample.

Public Sub DeleteGraphicsByName(ByVal pMxDoc As IMxDocument, ByVal sElementName As String, Optional ByVal bRefresh As Boolean = False)

    'Delete the named graphics from the gra container
    Dim pGraCon As IGraphicsContainer
    Dim pElementProp As IElementProperties
    Dim pElement As IElement

    ' Get the graphics container
    pGraCon = pMxDoc.FocusMap

    'Search for and delete the previous graphic by name
    pElementProp = pGraCon.Next
    Do Until pElementProp Is Nothing
      If pElementProp.Name = sElementName Then
        pElement = pElementProp
      End If
      pElementProp = pGraCon.Next

    If bRefresh Then
      pMxDoc.ActiveView.PartialRefresh(esriViewGraphics, Nothing, Nothing)
    End If

  End Sub
share|improve this answer
Thanks, got it working. – MapMan Jun 29 '12 at 14:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.