AnsweredAssumed Answered

Zoom to selected feature in Page layout

Question asked by hamad2 on Apr 14, 2013
Latest reply on Apr 18, 2013 by hamad2
I have text box in standalone application windows form application(ImapDocument)  for parcel No when user click on Search the listview populated with the Parcel Info.
it work fine, I am using  ImapDocument.
I need to zoom to this parcel  in page layout and export to PDF or jpg when user click on Create Map/Print Button.  I can't figure out how to do that.

I am using ArcgisDesktop 10.1

here is my code so far.

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click         License = New esriLicenseObj         License.Initialize_ArcInfo()         Try                        'strPath = "C:\Users\owner\Desktop\gis Dev\parcel.mxd" ' MXD path             Dim pMapdoc as ImapDocument = New MapDocument                         pMapDoc.Open("C:\Users\owner\Desktop\gis Dev\parcel.mxd")              'pActiveView = pMapDocument.PageLayout             'pActiveView.Activate(hWnd)             Dim pFeatureLayer As IFeatureLayer = CType(pMapDoc.Layer(0, 0), IFeatureLayer)             Dim featureName As String = pFeatureLayer.Name             Dim pMap As IMap             ''Dim pLayer As ILayer             Dim pActiveView As IActiveView             pActiveView = pMapDoc.PageLayout             pActiveView.Activate(GetDesktopWindow()) '(hWnd)              'Dim pFeatureLayer As IFeatureLayer             Dim pFeatureSelection As IFeatureSelection             Dim pQueryFilter As IQueryFilter               pMap = pMapDoc.Map(0) '  this is the solution                pActiveView = pMap              pQueryFilter = New QueryFilter              ''First layer in the map             'If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub             pFeatureLayer = pMap.Layer(0)             pFeatureSelection = pFeatureLayer 'QI              'Create the query filter             pQueryFilter = New QueryFilter             'pQueryFilter.SubFields = "PROP_ID"             pQueryFilter.WhereClause = "PROP_ID = '" & UCase(txtParcel.Text) & "'"              Dim pFClass As IFeatureClass = pFeatureLayer.FeatureClass              Dim pFCursor As IFeatureCursor = pFClass.Search(pQueryFilter, True)              'Invalidate only the selection cache             'Flag the original selection             pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)                 'Perform the selection             pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)             'Flag the new selection             pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)                      Dim pFeature As IFeature             pFeature = pFCursor.NextFeature              Dim nCols As Integer             nCols = pFeature.Fields.FieldCount             'define row             'Dim nRows As Integer             ''Me.Listsheet.ColumnHeaderCollection = nCols             'nRows = pFeature.Fields.FieldCount               For i = 2 To nCols - 1                 ' Me.lstResult.Items.Add(pFeature.Fields.Field(i).Name & "    " & pFeature.Value(i))                 Me.Listsheet.Items.Add(pFeature.Fields.Field(i).Name & "    " & pFeature.Value(i))                 'Me.tmpDT.DataSource(pFeature.Fields.Field(i).Name & "    " & pFeature.Value(i))                 'convertICursorToDataTable(tmpDT)             Next              ''Do not make any call to ArcObjects after ShutDownApplication()             ' Get the license back to the ArcInfo              ' License.ShutDown()             ''****************************************************************         Catch ex As Exception             MsgBox(ex.ToString)             Return         End Try         '******************************************************************************      End Sub

Thank you