Dock Window (vb.net) crashes upon feature selection

Discussion created by rmuellerjr03 on Apr 28, 2011
Latest reply on May 5, 2011 by chump4life
I have a PLSS form (SLO_DockableWindow1) with several comboboxes (section, township, township direction, range, and range direction) and a "Find" button. The comboboxes are populated through their item collection. When I click "Find" to run the query from the comboboxes, ArcMap crashes - every time. This has to be a problem with my overall vb.net coding. Any one see the problem?

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Desktop
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.DataSourcesFile
Imports ESRI.ArcGIS.Carto

Public Class SLO_DockableWindow1

    Public sMer As String
    Public sSection As String
    Public sTwp As String
    Public sRng As String
    Public sTwpD As String
    Public sRngD As String
    Public sUnit As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim pMap As IMap
        Dim pMxDoc As IMxDocument
        Dim pActiveView As IActiveView

        pMxDoc = My.ArcMap.Document
        pMap = pMxDoc.FocusMap

        sSection = Sec_cbo.Text
        sTwp = Twp_cbo.Text
        sTwpD = TwpD_cbo.Text
        sRng = Rng_cbo.Text
        sRngD = RngD_cbo.Text

        Dim sLayerName As String
        Dim pFeatureLayer As IFeatureLayer
        Dim i As Integer

        sLayerName = "PLSS"
        For i = 0 To pMap.LayerCount - 1
            If pMap.Layer(i).Name = sLayerName Then
                pFeatureLayer = pMap.Layer(i)
                Exit For
            End If
        Next i

        ' Create the query filter
        Dim pQueryFilter As IQueryFilter
        Dim SrchStr As String

        Dim pFeatureSelection As IFeatureSelection

        pQueryFilter = New ESRI.ArcGIS.Geodatabase.QueryFilterClass
        SrchStr = "PARCEL_ID='" & sSection & "'AND TWP'" & sTwp & "'AND TWPD='" & sTwpD & "'AND RNG='" & sRng & "'AND RNGD='" & sRngD & "'"
        pQueryFilter.WhereClause = SrchStr
        'Invalidate only the selection cache
        'Flag the original selection
        pActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)
        'Perform the selection
        pFeatureSelection.SelectFeatures(pQueryFilter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, False)
        'Flag the new selection
        pActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

    End Sub