Get field attribute problem

2011
10
Jump to solution
06-20-2012 06:04 AM
DaveCouture
New Contributor III
After selecting a feature through a query, I'd like a message box to pop up with 2 field values. This is what I have (in red):

 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)

        ' If PID found, Flag the new selection
        If featureSelection.SelectionSet.Count() = 0 Then
            MsgBox("Can't find the PID")
        Else
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
        End If

        ' Zoom to selected feature, if checkmarked
        If CheckBox1.CheckState = 1 Then
            Dim pUID As New UID
            pUID.Value = "esriArcMapUI.ZoomToSelectedCommand"
            My.ArcMap.Application.Document.CommandBars.Find(pUID).Execute()
        End If


        ' Display Owner's Name and PAN in message box
        Dim cursor As IFeatureCursor
        Dim feature As IFeature
        Dim patspan As String
        Dim taxname As String

        featureSelection.SelectionSet.Search(Nothing, False, cursor)
        feature = cursor.NextFeature
        patspan = feature.Fields.FindField("patspan")
        taxname = feature.Fields.FindField("taxname")

        Do Until feature Is Nothing
            MsgBox("PAN: " + feature.Value(patspan) + vbNewLine + "Owner's Name: " + feature.Value(taxname))
            feature = cursor.NextFeature
        Loop   
 End Sub

End Class
0 Kudos
10 Replies
DaveCouture
New Contributor III
Joe, thanks for your reply, but I had already tried that without success.  Instead of trying to get the selected feature in the cursor, it's just easier to re-perform the selection query, from the cursor; as Ken pointed out.

cursor = featureLayer.Search(queryFilter, False)
0 Kudos