I am trying to migrate my program from ArcMap 10 VBA to ArcObjects VB.net add-in in Visual studio express 2008. I write a ArcGIS addin component tool to draw a geometry, perform a spatial query and then pop out a windows form with radio buttons to decide based on which layers in TOC to perform the query. Now what I have encountered is in OnMouseDown Event the radiobutton read from current form and return no value. when I execute the code it opens the form as i expected but doesn't allow me to select radiobutton, besides it doesnot show any error or relevant warnings in VS express errorlist.

Here are the codes in Tool Class

Public Class Tool1
Inherits ESRI.ArcGIS.Desktop.AddIns.Tool
Dim frm2 As New Form2

Public Sub New()

End Sub

Protected Overrides Sub OnUpdate()
    Enabled = My.ArcMap.Application IsNot Nothing

End Sub

Protected Overrides Sub OnMouseDown(ByVal arg As ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs)

    ' MyBase.OnMouseDown(arg)
    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")

    'Determine Selection Layer based on which scale
    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)
    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
         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
     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)

    ' Set Array to Store Feature Value
    Dim NameValueArray() As String
    ReDim NameValueArray(pFeatureClass.FeatureCount(pSFilter))

    'Find Fieldindex to read Tile's Map Name

    Dim intFieldIndex As Integer
    intFieldIndex = pFeatureClass.FindField("TILE_NAME")

End Sub

End Class

Hope I can get some clue.thanks.


  • Have you tried using the debugging features in VS to see what is actually happening?
    – blah238
    Sep 19, 2012 at 13:11

2 Answers 2


Rather than try to pick apart your code I will just offer some general suggestions:

You will probably want to use a list or dictionary data structure or XML to store your layer names/workspaces and use data binding to bind the list to your user interface. You might consider using a dropdown list or list view instead of radio buttons if there are more than a handful of choices.

You might also consider using WPF instead of WinForms as its data binding features are much better and it is a more modern UI framework.

Lastly I would suggest searching or posting to StackOverflow for general programming questions, which is the impression I get from this one -- of course often times when doing GIS programming there is a gray area of whether it's a programming question or a GIS question so it is up to you to decide the best course of action.

  • thank you so much blah238, I'll take your advice to use dropdown component and try WPF. As a beginner of .NET programming, it is so glad to see your detailed answer.:D
    – user10283
    Sep 20, 2012 at 9:12

You open your form with the .Show method. This method opens the form as modeless, and then continues to execute the remainder of the code without waiting for user input. Therefore no selection is made in the form and nothing happens. The form remains open but clicking a radio button gives no action because the code has finished running already.

How to: Display Modal and Modeless Windows Forms

You can change the design of your program to open this as a modal form using the .ShowDialog() method. Store the user input from this modal form in a property that can be accessed by the main routine.

  • Rich, I try Showdialog method today and it just solves my problem. But still I'm confused of the difference between form.show and form.showdialog. Maybe as you all suggest I should take more time on VB.net basics rather than hurry in AO development at the beginning. thanks a lot!
    – user10283
    Sep 21, 2012 at 1:43
  • Glad I was able to answer your question. The easiest way to explain showdialog is that when your Sub gets to that line of code it stops and waits for user input before continuing. Sep 21, 2012 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.