jinglifreya

How to determine layer by Radiobutton in VB.NET

Discussion created by jinglifreya on Sep 18, 2012
Hello,all
I am on a code migration program. I encounter some problems when I try to writethe OnMouseDown Event for a ToolButton. What I intend to do is pop out a form then let users decide layers, and then based on which layer they select, the toolbutton continues to a spatial query to do selection. Now I debug the codes I cannot select the radiobutton. I suppose maybe it is relevant to how I define and call the form, though i am not pretty sure. all the codes works well in VBA but fails in VB.net. Here are parts of the OnMouseDown codes.

    Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)
        Dim pMxDoc As IMxDocument
        Dim pMap As IMap
        Dim pActiveView As IActiveView
        pMxDoc = My.ArcMap.Document
        pActiveView = pMxDoc.FocusMap
        pMap = pMxDoc.FocusMap
            
        Call AddDataFromFile.AddShapeFile("\\Hkhkgsv02\GIS\Basemap\Database_Index", "B1k_index")
        Call AddDataFromFile.AddShapeFile("\\Hkhkgsv02\GIS\Basemap\Database_Index", "B5k_index")
        Call AddDataFromFile.AddShapeFile("\\Hkhkgsv02\GIS\Basemap\Database_Index", "B10k_index")
        Call AddDataFromFile.AddShapeFile("\\Hkhkgsv02\GIS\Basemap\Database_Index", "B20k_index")
 
        Dim pScreenDisplay As IScreenDisplay
        Dim pRubberEnv As IRubberBand

        pScreenDisplay = pActiveView.ScreenDisplay
        pRubberEnv = New RubberEnvelope
 

        Dim pEnvelope As IEnvelope
        pEnvelope = pRubberEnv.TrackNew(pScreenDisplay, Nothing)
        'Rectangle Display

        If pEnvelope.IsEmpty = True Then Exit Sub
        With pScreenDisplay
            .StartDrawing(pScreenDisplay.hDC, ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache)
            .FinishDrawing()
        End With
        Dim pGeometry As IGeometry
        pGeometry = pEnvelope

        'Build a Spatial Query Filter

        Dim pSFilter As ISpatialFilter
        pSFilter = New SpatialFilter
        pSFilter.Geometry = pGeometry
        pSFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains



        Dim frm2 As New Form2
        frm2.Show()
        Dim pFlayer As IFeatureLayer = New FeatureLayer
        If frm2.RadioButton1.Checked = True Then
                pFlayer = pMxDoc.FocusMap.Layer(FindLayerIndex.Find_Layer_Index("B1k"))
        ElseIf frm2.RadioButton2.Checked = True Then
                pFlayer = pMxDoc.FocusMap.Layer(FindLayerIndex.Find_Layer_Index("B5k"))
        ElseIf frm2.RadioButton3.Checked = True Then
                pFlayer = pMxDoc.FocusMap.Layer(FindLayerIndex.Find_Layer_Index("B10k"))
        ElseIf frm2.RadioButton3.Checked = True Then
                pFlayer = pMxDoc.FocusMap.Layer(FindLayerIndex.Find_Layer_Index("B20k"))
        End If
          MsgBox(pFlayer.Name)
        'Spatial Filter
        Dim pSelectionLayer As IFeatureSelection
        pSelectionLayer = pFlayer
        If pFlayer Is Nothing Then Exit Sub
        Dim pFeatureClass As IFeatureClass
        Dim pFCursor As IFeatureCursor
        pFeatureClass = pFlayer.FeatureClass
        pFCursor = pFeatureClass.Search(pSFilter, True)
 


It seems that the PFlayer is empty and the form is not okay to click radio button, it keeps poping out the message box i use for test without displaying any name. Attached is a capture of radiobuttons in the form.

Jing

[ATTACH=CONFIG]17755[/ATTACH]

Attachments

Outcomes