Populate combobox on startup with data layers from TOC

4138
3
03-01-2012 09:10 AM
MichaelCharpentier
New Contributor
I am new to the .NET methods of creating AddIns.  I want to populate a combobox with the data
layer names from the table of contents when I open an ArcMap project.  I am using ArcMap
Desktop 10, Visual Studio 2010, C#.
0 Kudos
3 Replies
PriyankaMehta
New Contributor
Hi,

Here is a VB code for it. You will have to write it on load event.


 Private Sub Tool_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ''''' Populates layer combo box. Iterates through TOC and populates the combo box with available layers
        On Error GoTo EH
     Dim pMxDoc As IMxDocument
    Dim pMap As IMap


        pMxDoc = My.ArcMap.Application.Document
        pMap = pMxDoc.FocusMap
        Dim pLayer As ILayer
        Dim i As Integer
        If pMap.LayerCount = 0 Then
            Exit Sub
        End If
        For i = 0 To pMap.LayerCount - 1
            pLayer = pMap.Layer(i)
            cmbLayer.Items.Add(pMap.Layer(i).Name)
        Next i
        Exit Sub
EH:
        Debug.Print(Err.Number & " " & Err.Description)
    End Sub





Please try searching for solution on forums and ESRI help documents before posting a thread.
You will find most of your problems are already asked and resolved.

Below is the link to archived forum
http://forums.esri.com/Search.asp?c=93

Its very useful especially in the beginning stage.
Hope it helps !


Regards,
Priyanka
0 Kudos
MichaelCharpentier
New Contributor
The problem I am having is how to code the event handling portion to respond to open document
event and then populate the combobox.  I have tried working with the code in the "How to listen
to document events" section of the Concepts and Samples page but I am not having any luck.  I
may not be putting the event handler code in the right location, should it go in with the combobox
class code?

   Again I am using C# in Visual Studio 2010, ArcMap 10.
0 Kudos
sapnas
by
Occasional Contributor III
Are you using Combobox Add in?If So, Refer below link which contains sample code for combobox addin.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Sample_Custom_selection...
0 Kudos