This is an ArcObjects-specific version of this question: Create Array From Selected Features Based on the Order in Which They Were Selected

Is there a way to get the selected FIDs of a feature layer, selected with the interactive selection tools, in the order that the features were selected?

I've tried both enumerating and getting cursors over the map's FeatureSelection, the layer's IFeatureSelection.SelectionSet, and the IDisplayTable.DisplaySelectionSet. All returned in ascending order, not selection order.

I suppose that you could listen to feature selection events and track this yourself, but I was surprised to find out none of the above methods listed the features in selection order!

  • 1
    From all the documentation I've read, there doesn't seem to be any sort exposure of the selection order, though it would seem logical that some sort of array is created with additional features being added as they are selected. Instead of doing this, then adding the FID as an included field in the array, they are simply creating the array and using the FID as the index for it, or that is what they are exposing. – Get Spatial Jun 21 '12 at 23:23
  • sadly no option provided in ArcObjects unless you do some workarounds like listening to selection changed event as you said.. – vinayan Jun 22 '12 at 6:03
  • or maybe not..its possible!! – vinayan Jun 22 '12 at 6:40

Can't reliably do it with an ArcGIS API. You have to listen to the Selection Events and keep track of it yourself. Sorry.

  • Cool, glad I wasn't missing something obvious. – blah238 Jun 22 '12 at 5:59


As other experienced users commented, the below method is only a workaround possible in Arcgis 9.3..This functionality is not documented and may not exist in other versions..

The IEditor.EditSelection method can be used to retrieve objects in selected order to an enumerator. refer link below..


The code below Worked for me in 9.3

IEditor sEditor = m_application.FindExtensionByName("ESRI Object Editor") as IEditor;
IEnumFeature enumFeature = sEditor.EditSelection;

List<int> oidList = new List<int>();
IFeature selFeature = enumFeature.Next();
for (int fCount = 0; fCount < sEditor.SelectionCount; fCount++)
    selFeature = enumFeature.Next();

List<string> strList = oidList.ConvertAll<string>(delegate(int i) { return i.ToString(); });
  • Nice one! Will have to try this. Sounds like this only works within an edit session though, correct? – blah238 Jun 22 '12 at 7:04
  • @blah238 - sadly yes..but probably its useful only in edit sessions.. – vinayan Jun 22 '12 at 7:39
  • 1
    it is just an implementation side effect. You cannot rely on this functionality since this is nowhere in the API contract :-/ It may break across SPs – Ragi Yaser Burhum Jun 22 '12 at 8:00
  • 1
    Doesn't work in 10.0 SP4 (returns in ascending order, not selection order) :( – blah238 Jun 22 '12 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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