AnsweredAssumed Answered

Button add-in problem (VB)

Question asked by davecouture on Jun 15, 2012
Latest reply on Jun 15, 2012 by ldonahue
I just had VS2010 installed with ArcGIS 10.  I???m trying to learn how the snippet works and I'm using the AddLayerToActiveView snippet, as a test subject. I seem to have problems invoking it, in a button.  What am I doing wrong?

Imports ESRI.ArcGIS.SystemUI Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Geodatabase Imports ESRI.ArcGIS.Catalog Imports ESRI.ArcGIS.Carto Namespace CustomUIElements     Public Class AddLayer         Inherits ESRI.ArcGIS.Desktop.AddIns.Button          Public Sub New()          End Sub          Protected Overrides Sub OnClick()              WHAT SHOULD I PUT HERE????                                     My.ArcMap.Application.CurrentTool = Nothing         End Sub          Protected Overrides Sub OnUpdate()             Enabled = My.ArcMap.Application IsNot Nothing         End Sub           Public Sub AddLayerToActiveView(ByVal activeView As IActiveView, ByVal layerPathFile As System.String)              If activeView Is Nothing OrElse layerPathFile Is Nothing OrElse (Not layerPathFile.EndsWith(".lyr")) Then                  Return              End If              ' Create a new GxLayer             Dim gxLayer As IGxLayer = New GxLayerClass              Dim gxFile As IGxFile = CType(gxLayer, IGxFile) 'Explicit Cast              ' Set the path for where the layerfile is located on disk             gxFile.Path = layerPathFile              ' Test if we have a valid layer and add it to the map             If Not (gxLayer.Layer Is Nothing) Then                  Dim map As IMap = activeView.FocusMap                 map.AddLayer(gxLayer.Layer)              End If          End Sub      End Class  End Namespace

Outcomes