Select set is full of null values when selecting many records

753
1
02-10-2012 03:15 AM
LionelSlade1
New Contributor
Hi,

I have this function which works fine when select a few hundred records, but fails when selecting more.  The pFeature is full of nulls when you select the larger number of records.  Backend is an SQL SDE server.

Anyone have any ideas?

      /// <summary>
        /// Selects geometry features from the Map
        /// </summary>
        /// <param name="pGeometry">the geometry you want to select by</param>
        /// <returns>A list of feature objects</returns>
        public List<IFeature> SelectFeaturesByShape(IGeometry pGeometry)
        {
            ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass();
            pSelectionEnvironment.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew;
            pMap.SelectByShape(pGeometry, pSelectionEnvironment, false);
            List<IFeature> list = new List<IFeature>();
            IEnumFeature pEnumFeature = pMap.FeatureSelection as IEnumFeature;
            IFeature pFeature = pEnumFeature.Next();
            while (pFeature != null)
            {
                list.Add(pFeature);
                string eventGuid = (string)pFeature.get_Value(pFeature.Fields.FindField("EVENT_GUID")); // just here for debugging
                System.Diagnostics.Debug.WriteLine(eventGuid);// just here for debugging
                pFeature = pEnumFeature.Next();
            }

            return list;
        }
0 Kudos
1 Reply
NeilClemmons
Regular Contributor III
From the developer help topic for IMap::FeatureSelection:

Note, only the shape field is guaranteed with the selection. This is the default and exists for performance reasons. The IMap::FeatureSelection property is typically used to draw the map selection, not access feature attributes. This is particularly noticeable with shapefiles and coverage but also in geodatabases if the selection is large enough. Use IEnumFeatureSetup::AllFields to set a flag indicating all fields be returned with the selection. If you want to loop through the map selection to perform an operation, it is typically best to access each layer's selection rather than the entire map's selection. See the example for a sample of each.
0 Kudos