queryFilter Count

417
2
Jump to solution
06-19-2012 05:01 AM
DaveCouture
New Contributor III
I'm trying to add a count to a Query, so I can pop a message if the count = 0 (didn't find the record). This is what I have:

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)

       
        ' Perform query count
        Dim value As Integer = 0
        value = featureLayer.GetFeatureCount(queryFilter)

        If value = 0 Then
            MsgBox("can't find PID")
        End If


        ' Flag the new selection
        activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)


    End Sub
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
Since you've already queried the feature layer to get the feature selection, why not use that instead of querying the feature layer again?

   If featureSelection.SelectionSet.Count() = 0 Then      MsgBox("can't find PID")    End If

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
Since you've already queried the feature layer to get the feature selection, why not use that instead of querying the feature layer again?

   If featureSelection.SelectionSet.Count() = 0 Then      MsgBox("can't find PID")    End If
0 Kudos
DaveCouture
New Contributor III
Thanks again, Ken!
0 Kudos