can you help ... regarding select row

771
5
07-17-2010 03:06 AM
FatimahAL-Habib
New Contributor
Hello everyone,
I have this code which I use to query attributes then show it to the map directly

I want to select to the queered result
also I want to zoom & Highlite the selected


what is the code I should use





        Dim pMap As IMap = Me.ActiveView.FocusMap
        Dim pFLayer As IFeatureLayer = PF.GetLayerByFClassName(pMap, "GIS_Map")
        Dim pGeoCol As IGeometryCollection = New GeometryBag
        Dim pQuery As IQueryFilter = New QueryFilter
        If Not pFLayer Is Nothing Then
            pQuery.WhereClause = "Map_Name='" & txt_search.Text & "'"
            Dim pFeatCursor As IFeatureCursor = pFLayer.Search(pQuery, False)
            Dim pFeat As IFeature = pFeatCursor.NextFeature
            Do While Not pFeat Is Nothing
                pGeoCol.AddGeometry(pFeat.Shape)
                pFeat = pFeatCursor.NextFeature
            Loop
            Dim pGeoBag As IGeometryBag = pGeoCol
            Dim pEnv As IEnvelope = pGeoBag.Envelope
            Me.ActiveView.Extent = pEnv
            Me.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pFLayer, Nothing)
        End If
0 Kudos
5 Replies
ThavitinaiduGulivindala
Occasional Contributor
Hi,
In order to select features, cast IFeatureLayer to IFeatureSelection interface and use SelectFeatures method on IFeatureSelection interface.
To zoom to the selection, either u can use the procedure u have described in the post or run the in-built 'Zoom To Selected Features' command programatically using ICommandItem interface.

Cheers,
Thaviti
0 Kudos
FatimahAL-Habib
New Contributor
many thanks thaviti,

I tried this code to perform the selection :
        pMxDoc = Application.Document
        pMap = pMxDoc.FocusMap
        pFeatSel = pMap.Layer(0)

        ' set up query filter with where clause
        pQF = New QueryFilter
        pQF.WhereClause = "POP2000 > 200000"

        ' perform selection
        pFeatSel.SelectFeatures(pQF, esriSelectionResultNew, False)
        pFeatSel.SelectionChanged()
        pMxDoc.ActiveView.PartialRefresh(esriViewGeography, Nothing, Nothing)


but the problem is I have this error : name is not declared with those :
Application.Document
esriSelectionResultNew
esriViewGeography



I don't know am I missing a refrence or something !
can you help ?
0 Kudos
ThavitinaiduGulivindala
Occasional Contributor
Hi,
I havent encounted the same error but it might be due to the availability of the Assemblies to the developer.
If you are using VBA in ArcMap (Via Tools-->Macros-->Visual Basic Editor), the following code works for me.

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFeatSel As IFeatureSelection
Dim pqf As IQueryFilter

Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pFeatSel = pMap.Layer(0)

' set up query filter with where clause
Set pqf = New QueryFilter
pqf.WhereClause = "shape_length > 200000"

' perform selection
pFeatSel.SelectFeatures pqf, esriSelectionResultNew, False
pFeatSel.SelectionChanged
pMxDoc.ActiveView.PartialRefresh esriViewGeography, Nothing, Nothing

If the above code still throws same error, try replacing the statements as shown below.

Application.Document - esriArcMap.Application.Document
esriSelectionResultNew - esriCarto.esriSelectionResultEnum.esriSelectionResultNew
esriViewGeography - esricarto.esriViewDrawPhase.esriViewGeography ( use esriViewGeoSelection instead of esriViewGeography or use both together)

Cheers
Thaviti
0 Kudos
FatimahAL-Habib
New Contributor
well
I tried the code
it didn't work .. I replaced them .. but I got the same problem

I am using .net 2008


thank you for your kind help
0 Kudos
ThavitinaiduGulivindala
Occasional Contributor
Hi,

If you are using VS 2008, you get the reference of running ArcMap application. The way of getting its reference changes from case to case. E.g. If you are using ICommand interface, then 'hook' variable on 'OnCreate' method gives you the application's reference.
Let me know your situation.

Cheers
Thaviti
0 Kudos