VB .net checkbox initial state

2476
0
06-10-2015 02:25 PM
JenniferHorsman
New Contributor

I have a checkbox control as part of a dockable window in VB .net that turns a particular layer's visibility on and off in ArcMap. The initial state is set to "unchecked". But, if I load the tool into ArcMap and use it when that layer is already visible, the checkbox works in reverse (checked when the layer is off and unchecked when the layer is on). Is there any way I can check the visibility of the layer when the tool is first loaded and then set the state of the checkbox?

I tried putting some code in Public Sub New() function for my dockable window, but this crashed ArcMap. Here is what I had (with 3 dots representing other code). My checkbox is named chkBasemap. In this simple example, I just assume the basemap layer I want to toggle the visibility of is always the second layer.

Public Class DockWinClimateTools

  Public Sub New(ByVal hook As Object)

        ' This call is required by the Windows Form Designer.

        InitializeComponent()

        AddItems()

        CheckStates()

        Me.Hook = hook

  End Sub

  Public Sub CheckStates()

        Dim pMxDoc As IMxDocument = My.ArcMap.Application.Document

        Dim pMap As IMap = pMxDoc.FocusMap

        Dim baseLayer As ILayer = pMap.Layer(1)

        If baseLayer.Visible Then

            chkBasemap.Checked = True

        Else

            chkBasemap.Checked = False

        End If

   End Sub

.

.

.

End Class

0 Kudos
0 Replies