I'm creating a tool in ArcMap 10 using a Windows form... its been a struggle (maybe some of you recognize the same themes in my questions) because this is the first time I've really messed with ArcObjects and VB.Net... either way I'm almost there!! (Largely thanks to a very helpful GIS community.)

The main chunk of the code works (grabs an attribute from one layer and assigns it to the "target" layers), and now I'm in the process of linking up the user parameters.

enter image description here

As it stands, the "NHD Reach Layer" combo box (cmbNHD) requires the source layer be in the table of contents (TOC).

The target layers, on the other hand, can either be in the TOC (through the "Target Layers" combo box (cmbTarget), or accessible through the GxDialog. Either way, the selections are placed in the list box (boxTarget).


    Dim pLayer As IFeatureLayer
    Dim pGxDataset As IGxDataset = pGxObjects.Next
    Do Until pGxDataset Is Nothing
        pLayer = New FeatureLayer
        pLayer.FeatureClass = pGxDataset.Dataset
        pLayer.Name = pLayer.FeatureClass.AliasName
        If Not boxTarget.Items.Contains(pLayer.Name) Then boxTarget.Items.Add(pLayer.Name)
        pGxDataset = pGxObjects.Next
End Sub

OK, so what I can't figure out, is how to form some "loopable" list from the items in the list box. The original code worked only with the items in the table of contents, and so it could loop through them all using this type of loop...

    For i = 0 To pMap.LayerCount - 1
        Dim pLayer = pMap.Layer(i)

...and just skipping the index number of the source layer ("NHD Reach Layer").

AND SO, I'm pretty sure I just need to create an enumeration of the layers in the list box, but I've only been able to dig up the IEnumLayers interface, and it seems as if that only works with the layers in the current map.

Any thoughts/ideas?

Also, I'm not sure if this is the place (though, I can't think of a better one), but when this is all finished, I was wondering if I could post the final code (the reason I ask is because it wouldn't really be a question). I've spent a good amount of energy trolling through forums and developer help files to find relatively simple answers in the form of examples, but usually they are snippets, which, when viewed out of context, can be confusing.

It's my belief that this code would be really helpful to anybody just getting started, because it offers few frills, and combines a lot of basic methods with some intermediates thrown in here and there.

  • If you want to share the code, why not make a blog post on how to work with ArcObjects. Create a account on for example blogger.com and add a link to the blog post (final code) in your questions... May 13, 2011 at 14:49
  • Layer names are not necessarily unique. Also since you're allowing user to browse for a featureclass, are you creating a layer from whatever they select in the gxdialog? Since your working with NHD, if you're using multiple gdb's each gdb will have same featureclass name. Instead of presenting a list of layers, maybe a list of targets would be better, where each target is a string representing the full path to the target featureclass. May 13, 2011 at 14:53
  • did you finally share your code? Could you post it, or some link? I would like to use a windows form like yours. Thanks in advance!!! Mar
    – Margaral
    Jan 28, 2012 at 18:19
  • Is "NHD Reach Layer" a "group layer" or inside of a composite layer in the TOC?
    – ericoneal
    Jan 29, 2012 at 16:59
  • Sorry for the delay, about 1 year I guess. Anyway, I did finish up the code, and will post the link on filedropper below. The tool basically takes an input feature and assigns it a new value equal to that of the unique value of the nearest nhd flowline... if that makes sense. filedropper.com/nhdreachgrab Jun 7, 2012 at 5:14

2 Answers 2


Why not create a .Net generic list and fill it with the layers, something like this:

dim layerList as List(Of ILayer) = new List(Of ILayer)
  • 1
    Once you've done that (and filled the list with the For i = 0 To pMap.LayerCount - 1 loop) you can iterate the list by using "for each layer in layerList"
    – jburka
    May 13, 2011 at 15:34

Have you considered handling this through an array?

You could load the array and store the layer name and workspace path in the array. You could then iterate through the array as needed. When you add and remove items to and from the array, reload the list box to populate it with the array items. (there are different ways of doing this depending on the type control and array) In ArcObjects there is also an iArray that stores a reference to the layer itself (or other objects) rather then a plain array. Looping through arrays is very fast so even if you need to repopulate your control with items every time an item is added to or removed from an array is very fast.


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.