[Visual Basic 6.0]' Get a reference to the first layer in the map
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureLayer
Set pFLayer = pMap.Layer(0)' Set the definition query of the layer
Dim pFLDef As IFeatureLayerDefinition
Set pFLDef = pFLayer ' QI from the FeatureLayer
pFLDef.DefinitionExpression = "SUB_REGION = 'Pacific'" ' set the definition expression
pMxDoc.ActiveView.Refresh ' refresh the map
' Make a selection on the Layer
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
pQueryFilter.WhereClause = "Pop2000 > 5000000" ' set the query filter
Dim pFSel As IFeatureSelection
Set pFSel = pFLayer
pMxDoc.ActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
pFSel.SelectFeatures pQueryFilter, esriSelectionResultNew, False ' apply the selectionpMxDoc.ActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing ' refresh the selection
' Create a new selection layer using the current selection
Dim pSelFLayer As IFeatureLayer
Set pSelFLayer = pFLDef.CreateSelectionLayer("Selection_Layer", True, vbNullString, vbNullString)
pFSel.Clear ' clear selection on original layer
pMap.AddLayer pSelFLayer ' add new layer to the map
[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button
in the upper-left corner of the page.