How do I get all values of a specific field of a feature class in ArcObjects (c#.net)? Is there any way to select all features using IQueryFilter interface?


1 Answer 1


You have provided two different questions, however I assume you want to get the values from a specific field, having selected all features. Using IQueryFilter, I would suggest the following:

//You have to get a feature layer, let's assume you have selected one  
//in mxd document:

IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument;

IFeatureLayer2 pFeatureLayer = pMxDoc.SelectedLayer;

//then, you want to get feature class as follows:

IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

//I also assume, you want to get all NOT NULL values, 
//otherwise you don't need IQueryFilter, instead provide parameter null
//"Field_Name" is specified field, as follows:

IQueryFilter qF = new QueryFilter();
qF.WhereClause = "Field_Name IS NOT NULL";
IFeatureCursor pFeatureCursor = pFeatureClass.Search(qF, true);

//now loop through features to get all values e.g in the list
//note - values will be stored in string list listValues in my case 
//whereas an empty string "" from the list, indicates null

idxField = pFeatureClass.Fields.FindField("Field_Name");
IFeature pFeature = pFeatureCursor.NextFeature();
List<string>ValuesList = new List<string>();
string value;
while(pFeature !=null)
value = pFeature.get_Value(idxField).ToString();
pFeature = pFeatureCursor.NextFeature();

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