Disabling an Add-in ComboBox

450
3
12-12-2013 05:39 AM
Highlighted
New Contributor III
I created a VB.NET Add-In tool that adds layers to the map, from a Layer List ComboBox.  Everything works fine, but I do not want the tool to work when in Layout View. I know how to verify if I'm in the Layout View and display a message, but I would like to disable the ComboBo, instead of a message box. How can I modify my code to accomplish this?

        If TypeOf My.ArcMap.Document.ActiveView Is IPageLayout Then
            MsgBox("Switch to Data View to run the tool")
            Return
        End If
Reply
0 Kudos
3 Replies
Highlighted
MVP Honored Contributor
** wrong reply **
Reply
0 Kudos
Highlighted
New Contributor III
Finally found the answer here: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000000zz000000

I have to use the Update() method. This is my code:

   
    Protected Overloads Overrides Sub OnUpdate()
        ' Disabled if in Layer View
        If TypeOf My.ArcMap.Document.ActiveView Is IPageLayout Then
            Me.Enabled = False
        ElseIf TypeOf My.ArcMap.Document.ActiveView Is IMap Then
            Me.Enabled = True
        End If
    End Sub
Reply
0 Kudos
Highlighted
Occasional Contributor II
Hi, is there a way you can share the code that adds the layers in your combobox please? Also how can you make the combobox selects by default the first layer in the list?
Reply
0 Kudos