Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
duplicated or replaced with a new reference? –  steffan Jan 15 '13 at 18:31
    
yes replaced with a new reference –  Jagadesh Jan 15 '13 at 18:34
add comment

1 Answer

up vote 2 down vote accepted

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);
share|improve this answer
    
Thank you problem solved but what actually happening when i replaced true with false plz.. –  Jagadesh Jan 15 '13 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 Jan 15 '13 at 18:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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