I have a tool in ArcObjects that I'm working on where the OnClick() method finds the current row in the active attribute table (not the selection, but the row that has the carat to the left of the left most column), changes the current row to the next one in the attribute table, selects that feature, and then pans to it (basically the same as right clicking on a row, and selecting "Pan To" from the context menu).

If I use a search cursor or a selection set (either from the IFeatureLayer or the IDisplayTable interfaces) to iterate through the list, it only returns the rows in numerical order according to the ObjectID field. In most cases this suits our purposes, and I currently have this working.

However, in instances where the table is sorted by another field beforehand (say, a name field), is there a way to have a cursor or selection set that respects a sort done on the table before my tool is run?

I looked at ITableSort, but it seems to apply to performing a sort instead of what I want to do. I'm currently running ArcGIS 10.2.1.

2 Answers 2


There is no way to check how attribute windows is sorted. None of IAttributeWindow or IAttributeWindowEvents have methods to get the current sort options of attribute windows.

You can either use IQueryFilterDefinition2 or ITableSort (Prefered).

Note that, the ITableSort interface can only be used to sort tables that have an ObjectID field.


IQueryFilter queryFilter = new QueryFilterClass();
// Use the PostfixClause to alphabetically order the set by name.
IQueryFilterDefinition2 queryFilterDef = (IQueryFilterDefinition2)queryFilter;
queryFilterDef.PostfixClause = "ORDER BY nameField";

var cursor = table.Search(queryFilter, false);

ITableSort with a ISelectionSet ((assuming you have a featureClass, selSet, fieldName)

var table = (ITable) featureClass;
ITableSort tableSort = new TableSortClass();
tableSort.Fields = "fieldName";
tableSort.SelectionSet = selSet;

tableSort.set_Ascending("fieldName", true);
IEnumIDs enumIDs = tableSort.IDs;
while ((id = enumIDs.Next()) != -1)
    var feat =  featureClass.GetFeature(id);
    //Pan to the feat

I don't think there is a way to do this. In these situations, it is usually best to not make any assumptions about the table order and always perform the sort you want before iterating through the table.

As you suggested, ITableSort will do this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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