Set ActiveView extent to Selected Feature (ArcObjects)

705
2
09-09-2011 02:40 PM
ArtFreda
New Contributor
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();
0 Kudos
2 Replies
BenAller
New Contributor III
What version of ArcMap are you using?  That example is for version 8.1.
0 Kudos
ArtFreda
New Contributor
Version 9.3
0 Kudos