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 does not work. What am I doing wrong?

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;