davidclarke

Sorting in memory layer by descending order

Discussion created by davidclarke on Nov 2, 2012
Latest reply on Nov 5, 2012 by davidclarke
I am creating an in memory layer that I wish to sort.  I've tried to search the forums and have had no luck.  The documentation says there are some limitations with in memory layers but it does not list this specifically.  I followed the code sample given by the ESRI documentation but it does not seem to work.  The first record the cursor returns in the first record in the table; based on the sort I am attempting, it should be the last record returned.  The values are date/time stored in a field defined as (string).  Here are some examples of the values:
20121101143359
20121101143400

I saw a few samples where people set the "Table" property before or after setting the "Fields" and "Ascending" properties.  Notice I am trying to sort by descending order.  I get no errors.

        Dim perimeterClass As ESRI.ArcGIS.Geodatabase.IFeatureClass
        Dim geoFeatLayer As ESRI.ArcGIS.Carto.IGeoFeatureLayer
        Dim featureCursor As ESRI.ArcGIS.Geodatabase.ICursor
        Dim feature As ESRI.ArcGIS.Geodatabase.IFeature
        Dim currentIndex As Int32 = 0
        Dim tableSort As ESRI.ArcGIS.Geodatabase.ITableSort

        perimeterClass = _perimeterLayer.FeatureClass
        geoFeatLayer = _perimeterLayer

        If geoFeatLayer Is Nothing OrElse geoFeatLayer.FeatureClass.FeatureCount(Nothing) < MaxCalls Then
            Return
        End If

        tableSort = New ESRI.ArcGIS.Geodatabase.TableSortClass()

        tableSort.Fields = _keyFieldName
        tableSort.Ascending(_keyFieldName) = False
        tableSort.Table = CType(perimeterClass, ESRI.ArcGIS.Geodatabase.ITable)
        tableSort.Sort(Nothing)

        featureCursor = tableSort.Rows

        feature = featureCursor.NextRow()

Outcomes