By using the QueryFilter I am getting some features based on the query and I am placing that feature names in a listbox. When the user selects a particular name in the listbox that feature has to be zoomed to in the map.

Below is my code:

IQueryFilter pQueryFilter = new QueryFilterClass();
            pQueryFilter.WhereClause = textBox1.Text + textBox2.Text;
            ICursor pCursor = pFeatureClass.Search(pQueryFilter, true) as ICursor;
            IRow pRow = pCursor.NextRow();
while (pRow != null)
                pRow = pCursor.NextRow();


Here is what I tried:

IActiveView pActiveView = pMxDocument.ActiveView;
            IGeometry pGeometry = pFeature.Shape;
            IEnvelope pEnvelope = pGeometry.Envelope;

            pActiveView.Extent = pEnvelope.Expand(1.2, 1.2, true);

But I am unable to zoom.

  • so feature is not selected in the map.right?
    – vinayan
    Jan 10, 2013 at 7:59
  • Do you want to select the feature and highlight it or just zoom the map?
    – Emi
    Jan 10, 2013 at 8:36
  • I want to zoom that feature which i selected in ListBox
    – Jagadesh
    Jan 10, 2013 at 8:39
  • @Jagadesh - please post where you are going wrong..
    – vinayan
    Jan 10, 2013 at 10:09
  • @Jagadesh I added some comment in my answer. may be you missed it. you need to pass false in the expand method's third argument and you have to refresh arcmap's active view. For experimental please use pEnvelope.Expand(10, 10, false);
    – Emi
    Jan 10, 2013 at 11:10

4 Answers 4


This is not tested.

public void ZoomTo(IGeometry geometry)
    IMxDocument doc = (IMxDocument)ArcMap.Application.Document;
    IMap map = (IMap)doc.FocusMap;
    IActiveView pActiveView = (IActiveView)map;     
    IEnvelope pEnvelope;

    if (geometry is IPoint)
          IEnvelope currentEnv = pActiveView.Extent;
          IPoint point = (IPoint)geometry;
          pActiveView.Extent = currentEnv;
          map.MapScale = 100; //to set the scale to 1:100         
        pEnvelope = geometry.Envelope;
        pEnvelope.Expand(1.2, 1.2, true);

        pActiveView.Extent = pEnvelope;

  • Now i want to zoom to some collection of features where all are point features then how to work with it.
    – Jagadesh
    Jan 16, 2013 at 12:09
  • check snipplr.com/view/48443
    – vinayan
    Jan 16, 2013 at 12:32
  • 1
    If the geometry coordinate system is geographic and geometry type isn't point, then pEnvelope.Expand(1.2, 1.2, true); will zoom to a very big extent. May 2, 2015 at 14:19

Try the following (assuming names are unique):

  1. Store the feature reference returned by pFeatureClass.Search(pQueryFilter, true).NextFeature() in a hashtable (data structure is not important), with key=name & value=actual feature object
  2. On the selection changed event for the list, call
    pActiveView.Extent=(hashtable[SelectedListItem] as IFeature).Extent
  3. This should zoomt to the feature (but wont select it upon zooming)
  • I slightly changed my code instead of ICursor i have taken IFeatureCursor from that i am getting IFeature i tried but its not zooming to the feature
    – Jagadesh
    Jan 10, 2013 at 8:51
  • I saw that, any specific reason for it...do you intend to re-use it later?
    – ujjwalesri
    Jan 10, 2013 at 8:52
  • if the Geometry is an IPoint, it may not zoom..you might have to apply a buffer i think..
    – vinayan
    Jan 10, 2013 at 8:55
  • You could store the feature reference directly in the ListView using its ListViewItem.Tag property. Just be sure to use a non-recycling cursor.
    – blah238
    Jan 10, 2013 at 8:56
  • @vinayan yes it is point feature how to zoom now
    – Jagadesh
    Jan 10, 2013 at 9:10

You could also use the IHookActions interface for this, e.g.:

hookActions.DoAction(feature.Shape, esriHookActions.esriHookActionsZoom)

See also this sample: Using HookActions in custom commands

  • HookAction is the only method to zoom ? because i am beginner and not aware of hookactions
    – Jagadesh
    Jan 10, 2013 at 9:28
  • 2
    There are at least 3 ways to skin this cat... I am just offering one more.
    – blah238
    Jan 10, 2013 at 9:34
  • This is only applicable to ArcEngine and no the Desktop May 2, 2015 at 14:20
  • @FaridCher Are you sure? I remember testing it with ArcMap and it worked fine.
    – blah238
    May 4, 2015 at 19:52
  • I haven't tested this with Desktop. But If you open IHookActions documentation (your own link), you will only see Arc Engine under Product Availability! May 4, 2015 at 21:26

you just have to find out which feature the user selected.

ADDITION: May be for point feature the extent is so small that map can not zoom that much. So you need to make an envelope of that point and expand it as much as the map needs.

For point features:

IGeometry pointGeo = selectedFeature.Shape;
IEnvelope envelope = pointGeo.Envelop;
map.ActiveView.Extent = envelope;

see more fore IEnvelope.Expand Method. This should work.

  • I want to zoom that feature in Map at minimum map scale
    – Jagadesh
    Jan 10, 2013 at 8:56
  • @Jagadesh what do you mean by "minimum map scale"? Also, no such requirement was not stated up front (a bit unfair).
    – blah238
    Jan 10, 2013 at 8:58
  • For a particular Layer in a Map there are huge amount of Features placed. By querying particular fields i want to zoom that particular feature which user selected.
    – Jagadesh
    Jan 10, 2013 at 9:04
  • Okay... so you want to zoom to a feature. We got that part. What do you mean by "minimum map scale" is there a minimum scale level (e.g. 1:1200) that you don't want to automatically zoom below?
    – blah238
    Jan 10, 2013 at 9:04
  • (e.g. 1:2) so that we can see only that feature
    – Jagadesh
    Jan 10, 2013 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.