I have a Street_Light shapefile. It contains a field (POLE_TYPE).

POLE_TYPE can only have two values: "concrete" or "iron"

I am trying to select POLE_TYPE=iron.

When I tried manually by selecting by attributes, it showed 454 features but when my code run it selects only one feature.

Where did I go wrong?

Here is my code:

ESRI.ArcGIS.ArcMapUI.IMxDocument mxd = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument;
ESRI.ArcGIS.Carto.IMap map = mxd.FocusMap;
for (int i = 0; i < map.LayerCount; i++)
    ESRI.ArcGIS.Carto.ILayer lay = map.Layer[i];
    if (map.Layer[i].Name == "Street_Light")
        ESRI.ArcGIS.Carto.IFeatureLayer flay = lay as ESRI.ArcGIS.Carto.IFeatureLayer;
        ESRI.ArcGIS.Carto.IFeatureSelection fsel = flay as ESRI.ArcGIS.Carto.IFeatureSelection;

        ESRI.ArcGIS.Geodatabase.IQueryFilter qfltr = new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
        qfltr.WhereClause = "POLE_TYPE ='IRON'";
        ESRI.ArcGIS.Geodatabase.IFeatureCursor cur = flay.Search(qfltr, true);
        ESRI.ArcGIS.Geodatabase.IFeature fea = cur.NextFeature();
        while (fea != null)
            fsel.SelectFeatures(qfltr, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd, true);
            fea = cur.NextFeature();

1 Answer 1


The last parameter for IFeatureSelection.SelectFeatures, justone, indicated if you want to select just one (true) or all (false) features that satisfy the query filter. You would need to set it to false

fsel.SelectFeatures(qfltr, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultAdd, false);

Also, since you are not adding selected features one by one but rather using the query filter, you can remove the loop while (fea != null) and associated cursor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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