I'm stuck on how to collapse all layers in my ArcMap projects (9.3). I've tried a few bits of sample code, but they all seem to fail for some reason or other.
Some of the layers might be grouped, and some are imagery or WMS layers if that makes a difference.
Here is some code I have tinkered with, but does not work:
Dim pMxdoc As IMxDocument
Set pMxdoc = ThisDocument
Dim pFeatLayer As IFeatureLayer
Dim pEditLayers As IEditLayers
Set pEditLayers = pEditor
Dim pMap As IMap
Set pMap = pMxdoc.FocusMap
Dim pLayer As ILayer
'Collapse any expanded grouplayers
Dim pGroupLayer As IGroupLayer
For i = 0 To pMxdoc.FocusMap.LayerCount - 1
Set pLayer = pMxdoc.FocusMap.Layer(i)
'Check if the reached layer is a group
If TypeOf pLayer Is IGroupLayer Then
Set pGroupLayer = pLayer
if pGroupLayer.Expanded = true Then
pGroupLayer.Expanded = false
End if
End If
Next i
pMxdoc.UpdateContents
pMxdoc.ActiveView.Refresh
pGroupLayer.Expanded = false
? That's the syntax for C#, so just taking a stab at it.