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.

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!

share|improve this question
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
add comment

2 Answers

up vote 2 down vote accepted

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

share|improve this answer
    
Cool, glad I wasn't missing something obvious. –  blah238 Jun 22 '12 at 5:59
add comment

Edit:

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..

IEditor.EditSelection

The code below Worked for me in 9.3

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

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

List<string> strList = oidList.ConvertAll<string>(delegate(int i) { return i.ToString(); });
System.Windows.Forms.MessageBox.Show(string.Join(Environment.NewLine,strList.ToArray()));
share|improve this answer
    
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
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.