Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to regenerate a Legend in a Pagelayout whenever the layers visibility are changed in the TocControl. What is the best way to catch when a layer visibility is changed?

share|improve this question
up vote 4 down vote accepted

Watch for the VisibilityChanged event on the feature layer that you want to track.

Something like the following (taken from here):

private ILayerEvents_Event pLayerEvents;

void mActiveViewEvents_ItemAdded(object Item)
    if (Item is ILayerEvents_Event)            
        pLayerEvents = Item as ILayerEvents_Event;
        pLayerEvents.VisibilityChanged += new ILayerEvents_VisibilityChangedEventHandler(pLayerEvents_VisibilityChanged);

void pLayerEvents_VisibilityChanged(bool currentState)
    //do something here

A little more information is available here and here.

The links provided above point to ArcGIS 9.x content. If you plan on using ArcGIS 10, documentation is available here.

share|improve this answer
ArcGIS 10 documentation is over this way:… – Herb Sep 20 '10 at 14:28
The sample only workes on the root level layers, so the only way to catch change in visibility is by adding an event listener on every layer? – MathiasWestin Sep 20 '10 at 14:41
@Herb Thanks, updated. @MatthiasWestin As far as I know, that's correct. Since this is a layer-level event, each layer you want to track must be tracked individually. I "solved" this by creating a single method to track all layers, then point to that method when adding the event. – Michael Todd Sep 20 '10 at 15:06
@Michael-Todd Ok, I make a recursive method looping through the composite and group layers. The Sample code is incorrect the if-statement should check for ILayer or even better ILayerEvents_Event, best regards. – MathiasWestin Sep 20 '10 at 15:16

Your Answer


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.