AnsweredAssumed Answered

Get field attribute problem

Question asked by davecouture on Jun 20, 2012
Latest reply on Jun 20, 2012 by davecouture
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
        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")
            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"
        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
End Sub

End Class