English

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

Summary

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

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

Note:
This article pertains to ArcGIS versions 8.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

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'
  1. Right-click the UIButtonControl and select View Source.
  2. Copy this code into the UIButtonControl's click event.
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 

  1. Click AddData to add a layer to ArcMap.
  2. 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 programmatically selects the first feature.
  3. Click the button to run the code. Notice that the display shows the feature that you selected plus the feature that was selected programmatically.
  4. Right-click the UIButtonControl and select View Source.
  5. Locate the following lines of code.
' ***** When PartialRefresh isn't called
' before ClearSelection, the Map does not refresh correctly.

' pAV.PartialRefresh esriViewGeoSelection, pFeatLay, Nothing

' ******
  1. Uncomment the line that calls the PartialRefresh method.
  2. From the Selection menu, click Clear Selected Features.
  3. From the Tools toolbar, click the 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.
  4. Click the button to run the code. Notice the display shows only the feature that was selected programmatically.