Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Greetings,

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
    Loop
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. Just trying to help.

Thanks so much!!

DR

share|improve this question
    
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... –  MathiasWestin May 13 '11 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. –  Kirk Kuykendall May 13 '11 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 '12 at 18:19
    
Is "NHD Reach Layer" a "group layer" or inside of a composite layer in the TOC? –  ericoneal Jan 29 '12 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 –  DuncanRager Jun 7 '12 at 5:14
add comment

2 Answers

up vote 3 down vote accepted

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)
layerList.Add(layer)
share|improve this answer
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 '11 at 15:34
add comment

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.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004200000086000000

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.