Hi All,
I try this code to zoom to selected features but it zooms to nothing and the map becomes blank, what is the problem, please help me??
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Try
pActiveview = AxPageLayoutControl1.ActiveView
Dim pMap, pmap2 As IMap
pmap2 = pActiveview.FocusMap
pMap = AxTOCControl1.ActiveView.FocusMap
pmap2.ClearSelection()
pActiveview.Refresh()
If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub
pfeatureLayer = pMap.Layer(0)
pfeatureselection = pfeatureLayer 'QI
Dim where As String
' where = "GeoCode2 = '" & Blocks_List.SelectedItem & "'"
where = "GeoCode2 = '" & Blocks_List.SelectedItem & "'"
If Not pfeatureselection Is Nothing Then
Dim pQueryFilter As IQueryFilter = New QueryFilterClass()
pQueryFilter.WhereClause = where
pfeatureselection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, False)
' Dim pfeaturelayer2 As IFeatureLayer
' pfeaturelayer2 = pfeatureselection
Dim pSelSet As ISelectionSet
pSelSet = pfeatureselection.SelectionSet
Dim pEnumGeom As IEnumGeometry
Dim pEnumGeomBind As IEnumGeometryBind
pEnumGeom = New EnumFeatureGeometry
pEnumGeomBind = pEnumGeom
pEnumGeomBind.BindGeometrySource(Nothing, pSelSet)
Dim pGeomFactory As IGeometryFactory
pGeomFactory = New GeometryEnvironment
Dim pGeom As IGeometry
pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom)
' AxPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
AxPageLayoutControl1.ActiveView.Extent = pGeom.Envelope
'AxPageLayoutControl1.ActiveView.FocusMap.MapScale = 5593
AxPageLayoutControl1.ActiveView.Refresh()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub