Get Attributes from select feature on map using arcobjects

4987
3
01-06-2013 02:21 AM
shreyesshiv
New Contributor III
I want to get the attributes of the selected feature on mouse click from the map.
Please help me with a C# sample code
thanks
0 Kudos
3 Replies
ThavitinaiduGulivindala
Occasional Contributor
1. If you want to get all the selected features in Map then

// Reset to the first selected feature
ESRI.ArcGIS.Geodatabase.IEnumFeature enumFeature = (ESRI.ArcGIS.Geodatabase.IEnumFeature)map.FeatureSelection; // Explicit Cast  enumFeature.Reset();
ESRI.ArcGIS.Geodatabase.IFeature feature = enumFeature.Next();
  while (!(feature == null))
{
       //Do you job here//
    feature = enumFeature.Next();
}


2. If you want to get all the features selected in a Layer then make use of IFeatureSelection interface
0 Kudos
DannyDong
New Contributor III
However, IFeatureSelection doesn't work with IEnumFeature. What to do? I have to use ISelection instead. Are there any other ways?
0 Kudos
FridjofSchmidt
Occasional Contributor
However, IFeatureSelection doesn't work with IEnumFeature. What to do? I have to use ISelection instead. Are there any other ways?


If you start from a FeatureLayer, cast it to IFeatureSelection and get IFeatureSelection.SelectionSet. ISelectionSet.Search returns a search cursor that you can use to loop over all selected features in the layer.
0 Kudos