0

Based on the query i am getting some features in pFeatureCursor. I am adding that features into a List(IFeature). When iam iterating the pFeatureCursor and adding the values into pFeatureList all values in the list are replacing with the new reference pFeature

Please refer my code below

//List is declared globally
List<IFeature> pFeatureList = new List<IFeature>();

//In a method i am trying to add features in a list
//based on queryfilter
pFeatureCursor = pFeatureClass.Search(pQueryFilter, true);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
  pFeatureList.Add(pFeature);
  //lstQuerValue is the listbox
  lstQueryValue.Items.Add(pFeature.get_Value(1).ToString());

  //When below line is execute whatever the recent pFeature 
  //value is replacing all the items and duplicating in pFeatureList
  pFeature = pFeatureCursor.NextFeature();
 }

Please give some idea how to avoid it.

2
  • duplicated or replaced with a new reference?
    – steffan
    Commented Jan 15, 2013 at 18:31
  • yes replaced with a new reference
    – Jagadesh
    Commented Jan 15, 2013 at 18:34

1 Answer 1

4

If what's happening is that all the items in PFeatureList are the same, then try using a non-recycling cursor.

pFeatureCursor = pFeatureClass.Search(pQueryFilter, false);
2
  • Thank you problem solved but what actually happening when i replaced true with false plz..
    – Jagadesh
    Commented Jan 15, 2013 at 18:39
  • This determines what type of cursor your search method is returning. Read the API reference for IFeatureClass.Search and also look at resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/… under the section Understanding Recycling
    – kenbuja
    Commented Jan 15, 2013 at 18:52

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.