English

How To: Update ArcMap display when a feature selection is changed using IActiveview::PartialRefresh

Summary

When you call the PartialRefresh method on the IActiveView interface to update the display with a newly selected feature, you may find that the change is not reflected in the display. That is because IActiveView::PartialRefresh must be called twice, once before IMap::ClearSelection and once after.

Procedure

This VBA sample code illustrates how to call IActiveView::PartialRefresh both before and after IMap::ClearSelection to update the display correctly.
 

  1. Start ArcMap.
  2. Create a new UIButtonControl: How To: Create a new UIButtonControl​
    Note:
    For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  3. Right-click the UIButtonControl and select View Source.
  4. Copy this code into the UIButtonControl's click event.
     
    Code:
    Dim pApp As IApplication
    Set pApp = Application 
    
    Dim pMxDoc As IMxDocument 
    Set pMxDoc = ThisDocument 
    
    Dim pMap As IMap 
    Set pMap = pMxDoc.ActiveView 
    
    Dim pFeatLay As IFeatureLayer 
    Set pFeatLay = pMap.Layer(0) 
    
    Dim pFeatCursor As IFeatureCursor 
    Set pFeatCursor = pFeatLay.Search(Nothing, False) 
    
    Dim pFeat As IFeature 
    Set pFeat = pFeatCursor.NextFeature 
    
    Dim pAV As IActiveView 
    Set pAV = pMap 
    
    ' ***** When PartialRefresh isn't called  
    ' before ClearSelection, the Map does not refresh correctly.
    
    ' pAV.PartialRefresh esriViewGeoSelection, pFeatLay, Nothing 
    
    ' *****
    
    pMap.ClearSelection 
    pMap.SelectFeature pFeatLay, pFeat 
    
    pAV.PartialRefresh esriViewGeoSelection, pFeatLay, Nothing 
    
    
  5. Click AddData to add a layer to ArcMap.
  6. From the Tools toolbar, click the Select Features tool and select one feature. For this test, you want to select a feature that is not the first feature in the attributes table because the code will programmatically select the first feature.
  7. Click the button to run the code. Notice that the display shows the feature that you selected plus the feature that was selected programmatically.
  8. Right-click the UIButtonControl and select View Source.
  9. Locate the following lines of code.

    ' ***** When PartialRefresh isn't called
    ' before ClearSelection, the Map does not refresh correctly.

    ' pAV.PartialRefresh esriViewGeoSelection, pFeatLay, Nothing

    ' ******
  10. Uncomment the line that calls the PartialRefresh method.
  11. From the Selection Menu, click Clear Selected Features.
  12. From the Tools toolbar, click Select Features tool and select one feature. Select a feature that is not the first feature in the attributes table because the code will programmatically select the first feature.
  13. Click the button to run the code. Notice the display shows only the feature that was selected programmatically.