Iâ??m trying to create a simple Query, with VS2010. All I want to do is have a Selection by Attribute, using a Geodatabase Feature Class in the ActiveView. Iâ??m using the SelectMapFeaturesByAttributeQuery Snippet, but the code is a little unclear as to how I invoke the Feature Class by it's name, and not by order (Layer(0))
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Public Class Button1
Inherits ESRI.ArcGIS.Desktop.AddIns.Button
Public Sub New()
End Sub
Protected Overrides Sub OnClick()
SelectMapFeaturesByAttributeQuery(My.ArcMap.Document.ActiveView, ??????, "PID = '00000000'")
My.ArcMap.Application.CurrentTool = Nothing
End Sub
Protected Overrides Sub OnUpdate()
Enabled = My.ArcMap.Application IsNot Nothing
End Sub
Public Sub SelectMapFeaturesByAttributeQuery(ByVal activeView As IActiveView, ByVal featureLayer As IFeatureLayer, ByVal whereClause As System.String)
If activeView Is Nothing OrElse featureLayer Is Nothing OrElse whereClause Is Nothing Then
Return
End If
Dim featureSelection As IFeatureSelection = TryCast(featureLayer, IFeatureSelection) ' Dynamic Cast
' Set up the query
Dim queryFilter As IQueryFilter = New QueryFilterClass
queryFilter.WhereClause = whereClause
' Invalidate only the selection cache. Flag the original selection
activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
' Perform the selection
featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
' Flag the new selection
activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
End Sub