Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a problem with the method IActiveView.PartialRefresh which is not working as it should be (or I'm using it not correctly). I'm writing an ArcGIS 10 Add-In using C# and want to clear a selection. Here comes the code (taken from http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0049000000q5000000):

ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection;                                           
activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);
featureSelection.Add(feature);
activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null); // <-- this works

// perform some operation
...

// remove the selection
featureSelection.Clear();
activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null); // <-- does not work
// activeView.Refresh(); // <-- works

In the middle (where the ... are) I show a dialog and while this dialog is open the feature should be highlighted, so I select it. After closing the dialog it should no longer be selected, so I clear the selection (actually this bit is working, as I see when looking in the Selection Menu of ArcMap). But if I only do a PartialRefresh after the dialog has been closed, the selection is still visible. It only disappears if I make a full Refresh which doesn't look nice and is much slower.

Actually I also have the same problem with PartialRefresh (apart from any selection issues) when I only want to redraw a single layer

ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, featureLayer, null); <- doesn't work!!!

, but I'm not sure if these two problems are interlinked to each other.

I hope someone can help me with this problem...

share|improve this question
    
Are you by any chance doing this in Layout View? ESRI has been struggling with this for a long time. Might still not work correctly. Back in 2006 I was having similar issues in Layout and Neil Clemmons suggested calling PartialRefresh twice. Take a look at this link –  Jakub Mar 29 '12 at 17:40
    
Try adding the PartialRefresh method after the 'operation' and before clear the selection. –  user23574 Nov 3 '13 at 7:35
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Curlew Nov 3 '13 at 11:23

3 Answers 3

up vote 2 down vote accepted

This help document that you included suggests that you have to call ActiveView.PartialRefresh twice. I would suggest dropping in this new method and passing along your layer as an IFeatureLayer as opposed to trying to accomplish it all in one code block.

Basically, you need to PartialRefresh, Clear, and PartialRefresh again. Currently you only PartialRefresh and Clear.

///<summary>Clear the selected features in the IActiveView for a specified IFeatureLayer.</summary>
/// 
///<param name="activeView">An IActiveView interface</param>
///<param name="featureLayer">An IFeatureLayer</param>
/// 
///<remarks></remarks>
public void ClearSelectedMapFeatures(ESRI.ArcGIS.Carto.IActiveView activeView, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer)
{
  if(activeView == null || featureLayer == null)
  {
    return;
  }
  ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection; // Dynamic Cast

  // Invalidate only the selection cache. Flag the original selection
  activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);

  // Clear the selection
  featureSelection.Clear();

  // Flag the new selection
  activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);
}
share|improve this answer
    
Thanks for this - I completely misunderstood the help document. I thought that this method is only a stub and should be enhanced by the actual selection code before the first partial refresh - which is exactly what I did, but then one refresh is missing... –  geoSuleiman Mar 30 '12 at 13:14

I've often found more predictable results by getting the screen cache id for the particular draw phase (e.g. esriViewGeoSelection) and call IScreenDisplay.Invalidate(null, true, id).

share|improve this answer

To get this to work I had to add the mxDoc, map and activeView within the code again even though I have it elsewhere.

Public void ClearSelectedMapFeatures(ESRI.ArcGIS.Carto.IActiveView activeView, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer)
    {
        IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;
        IMap map = mxDoc.FocusMap;

        activeView = mxDoc.ActiveView;

        if (activeView == null || featureLayer == null)
        {
            return;
        }
        ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection; // Dynamic Cast

        // Invalidate only the selection cache. Flag the original selection
        activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);
        // Clear the selection
        featureSelection.Clear();

        // Flag the new selection
        activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);

    }
    #endregion
share|improve this answer

Your Answer

 
discard

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.