Private pFCursor As IFeatureCursor Private Sub UIButtonControl1_Click() Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pLayer As ILayer Dim pFLayer As IFeatureLayer Dim pFeature As IFeature Set pMxDoc = ThisDocument Set pMap = pMxDoc.FocusMap Set pLayer = pMap.Layer(0) Set pFLayer = pLayer If pFCursor Is Nothing Then Set pFCursor = pFLayer.FeatureClass.Search(Nothing, False) End If Set pFeature = pFCursor.NextFeature pMap.ClearSelection pMap.SelectFeature pLayer, pFeature pMxDoc.ActiveView.Refresh End SubMike.
To respect the definition query for a layer, use IFeatureLayer.Search.
Replace:
Set pFCursor = pFLayer.FeatureClass.Search(Nothing, False)
With:
Set pFCursor = pFLayer.Search(Nothing, False)
Hi there, Neil's method of getting the ObjectId is probably optimal if the featureclass is not being edited at the time. If it is you can probably do a search on the IfeatureLayer with a QueryFilter where objectid > theSelectedObjectID, get the first feature in the cursor and use that id.
As far as making the selection, I suggest you use IfeatureSelection.Clear, IFeatureSelection.SelectionSet.Add(ObjectId) and Call IfeatureSelection.ChangeSelection.
if you have no query definition and you have a very large featureclass (hundreds of thousands of records), it might actually be more efficient, to find the objectID from the selection (ISelectionSet.Ids), increment it can call IfeatureClass.GetFeature, trap the exception and keep going until you find a valid feature. Keep in mind error trapping in .Net is usually not efficient and to be avoided. However, this might be faster than running queries on very large tables.
I got an "Automation Error" when I tried changing this. If I remove the definition query this works fine, but put it back and I get Automation Error again. Leaving the 'FeatureClass' part in I don't get the Automation Error (but doesn't follow the definition query)
Mike.
Dim pTableDefinition As ITableDefinition Set pTableDefinition = pFLayer Dim pQueryFilter As IQueryFilter Set pQueryFilter = New QueryFilter pQueryFilter.WhereClause = pTableDefinition.DefinitionExpression pQueryFilter.SubFields = "*" ... Set pFCursor = pFLayer.FeatureClass.Search(pQueryFilter, False)
Interesting. What type of datasource are you working with? And what version of ArcMap?SDE point or line feature class, joined to SQL table, definition query on SQL table. ArcMap 10.0 (fully patched)