timpittser

Want to select feature on 'Mousedown' in vb.net 2010 and get attribute info

Discussion created by timpittser on Sep 5, 2013
I'm trying to migrate all my 9.3 code to 10.1 and am having trouble getting my selecting a feature to work.  Any assistance would be greatly appreciated.  Thanks.

            Dim pMap As IMap
            Dim mpPoint As IPoint
            Dim pGeometry As IGeometry
            Dim pBuffer As IGeometry
            Dim mapdoc As IActiveView
            Dim ptopo As ITopologicalOperator
            Dim x As Long, y As Long
            Dim pPoint As Double, i As Integer
            Dim m_pcurrentlayer As IFeatureLayer
            Dim pspatialfilter As ESRI.ArcGIS.Geodatabase.ISpatialFilter
            Dim pfeatureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass
            Dim pFeatureLayer As IFeatureLayer
            Dim pfilter As ESRI.ArcGIS.Geodatabase.IQueryFilter
            Dim pCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor
            Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature
            Dim flds As ESRI.ArcGIS.Geodatabase.Field
            Dim lgth As Double
            mapdoc = AxMapControl1.Map
            pMap = mapdoc.FocusMap
            mpPoint = mapdoc.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y)
            pGeometry = mpPoint
            lgth = ConvertPixelsToMapUnits(pMap, 4)
            ptopo = pGeometry
            pBuffer = ptopo.Buffer(lgth)
            pGeometry = pBuffer.Envelope
            For ii = 0 To pMap.LayerCount - 1
                If pMap.Layer(ii).Name = "Service Location" Then
                    m_pcurrentlayer = pMap.Layer(ii)
                    pFeatureLayer = m_pcurrentlayer
                    pfeatureClass = pFeatureLayer.FeatureClass
                    pspatialfilter = New ESRI.ArcGIS.Geodatabase.SpatialFilter
                    pspatialfilter.Geometry = pGeometry
                    Select Case pfeatureClass.ShapeType
                        Case esriGeometryType.esriGeometryPoint 'Query Geometry Contains Target Geometry
                            pspatialfilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelContains
                        Case esriGeometryType.esriGeometryPolyline 'Query Geometry Crosses Target Geometry
                            pspatialfilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelCrosses
                        Case esriGeometryType.esriGeometryPolygon 'Query Geometry Intersects Target Geometry
                            pspatialfilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects
                    End Select
                    pspatialfilter.GeometryField = pfeatureClass.ShapeFieldName
                    pfilter = pspatialfilter
                    pCursor = pFeatureLayer.Search(pfilter, False)
                    pFeature = pCursor.NextFeature
                    If Not pFeature Is Nothing Then MsgBox("It worked")
                End If
            Next

Outcomes