Hello - I am using Java Arcobjects (ArcGIS 10.0) to programatically deal with an MXD file. What I have are MXD files that contain feature layers listed at the root/base of the TOC. I am programmatically adding nested GroupLayers to MXD file and then I want to move the feature layers from the root/base to a nested GroupLayer. What I have initially done is successfully added the nested GroupLayers to the MXD file. If I remove the feature layer from the map document and then add it to the group layer, it works fine. The problem is that when I remove the feature layer, the legend is also updated with the removed layer no longer in the legend but when I then add the feature layer to the group layer, the legend is not updated, so the end result is that my MXD TOC looks fine, but the legend is missing my feature layer info. I can't find a way to either have the feature layer re-added to the legend when it is added to the GroupLayer or do something where the legend is never updated at all.
Thanks - Peter
UPDATE: I was finally able to get what I wanted but it seems that there should be an easier way. The only way to get the layers listed back in the legend was to wait until all of the layers were added to the group layers BEFORE adding the root group layers to the map via the map.addLayer() call. Simply adding the feature layer to a group layer via the grpLayer.add() call does not add the layer to the legend.
Anyway, all is working as I need.
Thanks - Peter
I did not see your earlier post. I noticed that you were able to get this working, but thought I would provide a possible solution if it could still be helpful. Have you tried using the IActiveView:contentsChanged method? I've had issues in the past with data added to the TOC in group layers and they were not showing up correctly and calling this method resolved it for me.
Hope it helps