Last map added won't collapse

1961
5
Jump to solution
02-29-2012 09:45 AM
SpencerGardner
New Contributor II
I'm having an issue with using Arcobjects to expand/collapse maps (data frames) in the TOC based on a selected value in a combo box. When a user changes the selection in the combo box, all maps should collapse except for the map that shares a name with the selected combo box. This works well with 1 or 2 maps in the document. With each additional map beyond 2, the last map added does not collapse.

For example, assume 2 maps - Map A and Map B. Expand collapse works well. If I add Map C and change the combo box to "Map A", only Map B collapses. If I add Map D and then change the combo box to "Map B", all maps collapse except Maps B and D.

        private void expandScenario(string scenarioName)         {             //collapse all data frames             for (int i = 0; i < m_maps.Count; i++)             {                 m_maps.Item.Expanded = false;             }             //expand the scenario's data frame             for (int i = 0; i < m_maps.Count; i++)             {                 if (m_maps.Item.Name == scenarioName)                 {                     m_maps.Item.Expanded = true;                 }             }             activateDataFrame(scenarioName);         }


I have ensured that the document is being updated via IMxDocument.UpdateContents() after making the call. I've checked to make sure the m_maps.Count accurately reflects the number of data frames. I have also checked to make sure m_maps.Item.Expanded = false is being run on the data frame that fails to collapse.

I have noticed that the data frame in question collapses immediately if I move its position in the TOC - perhaps I need to refresh the TOC but I thought calling IMxDocument.UpdateContents()
took care of that.
0 Kudos
1 Solution

Accepted Solutions
SpencerGardner
New Contributor II
If the selected element is one of the layers, the dataframe with the selected layer stays expanded. 


Ahh, there's the issue. I have a layer selected in the data frame that is not collapsing. Wouldn't it be nice for that information to be included in the documentation...

Is there an easy way to unselect any selected layers in the TOC? I tried the following but it doesn't work.

        private void expandScenario(string scenarioName)         {             //collapse all data frames             for (int i = 0; i < m_maps.Count; i++)             {                 IGraphicsContainerSelect graphics = (IGraphicsContainerSelect)m_maps.Item;                 graphics.UnselectAllElements();                 m_maps.Item.Expanded = false;             }             //expand the scenario's data frame             for (int i = 0; i < m_maps.Count; i++)             {                 if (m_maps.Item.Name == scenarioName)                 {                     m_maps.Item.Expanded = true;                 }             }             activateDataFrame(scenarioName);         }

View solution in original post

0 Kudos
5 Replies
AlexanderGray
Occasional Contributor III
I kicked it up quickly in vba with a simple map with 4 data frames with one layer each.  All four dataframes collapsed, provided the that selected element in the TOC is one of the dataframes.  If the selected element is one of the layers, the dataframe with the selected layer stays expanded.
Sub test()

Dim mxd As IMxDocument
Set mxd = ThisDocument
Dim i As Integer
For i = 0 To mxd.Maps.Count - 1
    mxd.Maps.Item(i).Expanded = False
Next
mxd.UpdateContents

End Sub
0 Kudos
SpencerGardner
New Contributor II
If the selected element is one of the layers, the dataframe with the selected layer stays expanded. 


Ahh, there's the issue. I have a layer selected in the data frame that is not collapsing. Wouldn't it be nice for that information to be included in the documentation...

Is there an easy way to unselect any selected layers in the TOC? I tried the following but it doesn't work.

        private void expandScenario(string scenarioName)         {             //collapse all data frames             for (int i = 0; i < m_maps.Count; i++)             {                 IGraphicsContainerSelect graphics = (IGraphicsContainerSelect)m_maps.Item;                 graphics.UnselectAllElements();                 m_maps.Item.Expanded = false;             }             //expand the scenario's data frame             for (int i = 0; i < m_maps.Count; i++)             {                 if (m_maps.Item.Name == scenarioName)                 {                     m_maps.Item.Expanded = true;                 }             }             activateDataFrame(scenarioName);         }
0 Kudos
AlexanderGray
Occasional Contributor III
yup use the removefromselecteditems on the icontentsview

Dim mxd As IMxDocument
Set mxd = ThisDocument

Dim ctView As IContentsView
Set ctView = mxd.ContentsView(0)
ctView.RemoveFromSelectedItems (ctView.SelectedItem)

Dim i As Integer
For i = 0 To mxd.Maps.Count - 1
    mxd.Maps.Item(i).Expanded = False
Next
mxd.UpdateContents
0 Kudos
SpencerGardner
New Contributor II
That did the trick. Thanks!
0 Kudos
AlexanderGray
Occasional Contributor III
You can mark it as resolved.  thanks
0 Kudos