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.

I have the following snippit of code to perform this. However, it doesn't do anything to the layer in the TOC on the map that gets generated from this code. When the layer is created and the map shows up, the layer appears expanded. I want it to collapse. Am I doing something wrong? Thanks.

        IMap aMap = axMapControl1.ActiveView.FocusMap;
        ILayer pLayer = aMap.get_Layer(0);
        INALayer2 anNALyr = (INALayer2)pLayer;
        anNALyr.Expanded = false;
        axTOCControl1.Refresh();

Also, how do I get a layer in the TOC to move to the bottom of the TOC?

share|improve this question

2 Answers 2

Renee,

Here is the VB version of how to move a layer to the bottom of the TOC.

'Move layer in the TOC

 Dim pMxDocument As IMxDocument

  Dim pContentsView As IContentsView

  Dim pMap as IMap

  Set pMxDocument = Application.Document

  Set pContentsView = pMxDocument.CurrentContentsView

  Dim pFocusMap As IMap

  Dim Layer1 As ILayer

  Dim Layer2 As ILayer

  Set pFocusMap = pMxDocument.FocusMap

  Set Layer1 = pFocusMap.Layer(0)



  Dim LayerSet As esriSystem.ISet

  Set LayerSet = New esriSystem.Set

  LayerSet.Add Layer1

  pContentsView.SelectedItem = LayerSet

  Dim i As Integer

  Dim pLayer As ILayer

  Set pMxDocument = Application.Document

  Set pMap = pMxDocument.FocusMap

  Set pLayer = pMxDocument.SelectedLayer


Dim ii As Long

Dim layerIndex As Long



For ii = 0 To pMap.LayerCount - 1

If pMap.Layer(i).name = pLayer.name Then

layerIndex = ii

End If

Next ii



pMap.MoveLayer pLayer, layerIndex - 1

Are you trying to collapse a single layer or a group layer?

share|improve this answer
    
Thank you. I'm all set with this now. I was able to accomplish what I needed to do in terms of moving and collapsing the layer in the TOC with the following code: –  Renee Cammarere Mar 10 '11 at 13:37
    
aMap.MoveLayer(pLayer, nLyrs - 1); INALayer2 anNALyr = (INALayer2)pLayer; anNALyr.Expanded = false; //Refresh the TOC and the map window activeView.ContentsChanged(); –  Renee Cammarere Mar 10 '11 at 13:38

You're question is similar to mine: Programmatically uncheck layer in AxTOCControl

The solution was to use the correct refresh method: IActiveView.ContentsChanged

For layer movement, use mapcontrol.map.MoveLayer()

share|improve this answer

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.