ssntails

Set ActiveView extent to Selected Feature (ArcObjects)

Discussion created by ssntails on Sep 9, 2011
Latest reply on Oct 20, 2011 by ssntails
I have an ISelectionSet. I want to do the same thing that 'Zoom to Selected Features' does, using my IActiveView.

The code at http://support.esri.com/en/knowledgebase/techarticles/detail/20913 does not work. What am I doing wrong?

mapdoc.ActiveView.Activate(0);
IQueryFilter qfilter = new QueryFilterClass();
            qfilter.WhereClause = "STR='" + strParam + "'";

            // Invalidates only the selection cache
            // Flag the original selection
            // Perform the selection
            IFeatureLayer fLayer = curMap.get_Layer(2) as IFeatureLayer;
            IFeatureSelection fSelection = (IFeatureSelection)fLayer;
            fSelection.SelectFeatures(qfilter, esriSelectionResultEnum.esriSelectionResultNew, false);

            // Zoom to the selection
            ISelectionSet pSelSet = fSelection.SelectionSet;
            IEnumGeometry pEnumGeom;
            IEnumGeometryBind pEnumGeomBind;
            pEnumGeom = new EnumFeatureGeometryClass();
            pEnumGeomBind = (IEnumGeometryBind)pEnumGeom;
            pEnumGeomBind.BindGeometrySource(null, pSelSet);

            IGeometryFactory pGeomFactory = new GeometryEnvironmentClass();
            IGeometry pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom);
            mapdoc.ActiveView.Extent = pGeom.Envelope;
            mapdoc.ActiveView.Refresh();

Outcomes