I can't seem to find anyone else with this problem, but I'm hoping maybe I'm missing something obvious!
I am writing an Editor Extension add-in using VB.net for ArcMap 10. The feature layer I'm rendering is from an SDE dataset.
Once the user starts editing, I use a unique value renderer to display features, omitting some (the client wants features they have classified as 'inactive' to disappear – without being deleted – and my understanding is that a definition query won't work in an edit session, so I have modified the symbology instead).
After I set the renderer, I want the display to refresh to show the new symbology. However, ActiveView.Refresh, ActiveView.PartialRefresh, and ScreenDisplay.Invalidate will not work. There is no error, but the screen does not refresh. I have stepped through using the debugger and confirmed that the program execution does reach those lines, but after 'executing' those lines nothing happens. The TOC updates properly, but the view does not. I can manually click the refresh button and it refreshes just fine, but I can't seem to make it work programmatically.
I have tried brute forcing it by using ActiveView.Deactivate followed by ActiveView.Activate, and this does cause a screen refresh, but then when I try to draw the point, the mouse pointer and the marker symbol indicating the potential location of the new point are offset by about 4 inches.
I'm completely at a loss here. Any ideas?
I've included an exerpt from my code below (this is done nearly identically for 4 feature layers, so normally the select case would have 3 more entries, but I simplified it for this post). Thanks!!
'define the colors to use in the renderers
Dim pOutlineColor As New ESRI.ArcGIS.Display.RgbColor
Dim pStructureColor As New ESRI.ArcGIS.Display.RgbColor
'make the structure outline color black
pOutlineColor.Red = 0
pOutlineColor.Blue = 0
pOutlineColor.Green = 0
'make the structure center color macaw green
pStructureColor.Red = 152
pStructureColor.Blue = 0
pStructureColor.Green = 230
'create the symbols
Dim pStructureSymbol As New ESRI.ArcGIS.Display.SimpleMarkerSymbol
'construct the structures symbol
pStructureSymbol.Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle
pStructureSymbol.Size = 4
pStructureSymbol.Outline = True
pStructureSymbol.OutlineSize = 1
pStructureSymbol.OutlineColor = pOutlineColor
pStructureSymbol.Color = pStructureColor
'define renderers
Dim pStructureRenderer As New ESRI.ArcGIS.Carto.UniqueValueRenderer
'set the fields used in the renderers - we'll just have one, the 'Active' field
'set usedefaultsymbol to false so that inactive features
'will not draw (i.e., if Active <> 1 or Null)
'structures renderer
With pStructureRenderer
.FieldCount = 1
.Field(0) = "Active"
.UseDefaultSymbol = False
'add "1" to the value list for the renderer - i.e., display "1" values using pStructureSymbol
.AddValue("1", "Active", pStructureSymbol)
.Label("1") = "Active"
'add "<Null>" to the value list for the renderer using the same symbology as "1"
.AddReferenceValue("<Null>", "1")
'tell it we're using our own custom style
.ColorScheme = "Custom"
'tell it the field type for the 'Active' field is not a string (it's an integer)
.FieldType(0) = False
End With
Dim pLayer As ESRI.ArcGIS.Carto.ILayer
Dim pFeatureLayer As ESRI.ArcGIS.Carto.IFeatureLayer2
Dim pGeoFeatureLayerStructures As ESRI.ArcGIS.Carto.IGeoFeatureLayer
'this makes the layer properties symbology tab show
'the correct interface.
Dim pPropertyPage As ESRI.ArcGIS.CartoUI.IRendererPropertyPage
pPropertyPage = New ESRI.ArcGIS.CartoUI.UniqueValuePropertyPage
Do Until pLayer Is Nothing
If TypeOf (pLayer) Is ESRI.ArcGIS.Carto.IFeatureLayer2 Then
pFeatureLayer = pLayer
If pFeatureLayer.FeatureClass.FindField("Active") > 0 Then 'only set the renderer if there is an 'active' field in the layer
Select Case pFeatureLayer.FeatureClass.AliasName
Case strStructuresLayerName
pGeoFeatureLayerStructures = pFeatureLayer
pGeoFeatureLayerStructures.Renderer = pStructureRenderer
pGeoFeatureLayerStructures.DisplayField = "Active"
pGeoFeatureLayerStructures.RendererPropertyPageClassID = pPropertyPage.ClassID
End Select
End If
pFeatureLayer = Nothing
End If
pLayer = pEnumLayers.Next
Loop
My.Document.ActiveView.ContentsChanged()
My.Document.UpdateContents()
My.Document.ActiveView.Refresh() 'this does nothing
'This also does nothing:
'My.Document.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewAll, Nothing, pActiveView.Extent)
'This also does nothing:
'My.ThisApplication.Display.Invalidate(My.Document.ActiveView.Extent, False, ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache)
'this makes the screen go blank:
'Dim pMaps As ESRI.ArcGIS.Carto.IMaps
'pMaps = My.Document.Maps
'My.Document.ActiveView = My.Document.PageLayout
'My.Document.ActiveView = pMaps.Item(0)
'My.Document.ActiveView.Refresh()
'this makes the cursor and the point to be drawn offset by about 4 inches:
'Dim pActiveView As ESRI.ArcGIS.Carto.IActiveView
'pActiveView = My.Document.FocusMap
'pActiveView.Deactivate()
'pActiveView.Activate(My.ThisApplication.Display.hWnd)
Best Answer
You might need to reference the active view of the ArcMap document via iMXDocument. Try this: