Wire TOC event

1138
4
09-01-2011 06:52 AM
AlexandraFairbarns
New Contributor III
Hi to all!

I am currently building an add-in for ArcGIS desktop. The add is a dockable window with tool functions. Part of the interface has a sections similar to the TOC in which groups of specific layers (included with the add-in) may be turned on and off. This event would need to turn off/on the layers simultaneously so that when the group is turned off in the dockable window, so it is in the TOC and vice verse.

I have it working as in dockable window syncing to TOC, but how do i listen for events from the TOC to update the dockable window.

I have been racking my brain for several days now, and not getting anywhere. I have found the snippet for editor events, and the visual studio project for new/open documents and have looked at the help support on event listening.....but am still very confused.

Essentially my questions are: where do i put the code for event listening i.e. top of my dockable window code? and how do i reference the TOC so i get events back? and will it slow the program down a lot to do this.

Would be so grateful is someone could give me an inclination or code for what to do...

Thank You so much

Alex
0 Kudos
4 Replies
AlexanderGray
Occasional Contributor III
In my experience I have found it much better to put event listeners on an extension.  Windows forms and controls can have unexpected consequences in terms of threading and event handling.  Performance should not be a major concern if you limit the processing in the event handler. 

If the event needs to trigger something on the dockable window control, I suggest you create your own custom events and set up the event listeners on the dockable control.  Have an extension with event handlers for the toc events and raise your custom event in the extension events.  Sounds a little convoluted but saves headaches in the long run.
To recap, this has worked for me in the past:
Dockable window: declare custom events and add handlers for them
Extension: add handlers to TOC events, in handlers raise custom events.
0 Kudos
AlexandraFairbarns
New Contributor III
Sounds a much better way of implementing it, have now attempted it this way around. My only problem now is handling the event...how exactly do i handle a TOC event such as rename or change of visibility of a layer so that it will fire custom response?

Cannot seem to find anything that interacts with the TOC specifically - most use workarounds like events.activeviewchanged.
0 Kudos
AlexandraFairbarns
New Contributor III
Ha HA...an element of success. Have been able to fire the event for renaming, visibility of TOC etc using active view events.....uses .contents changed and .view refreshed, did not use after redraw as fires far too many time for my liking.

Question remaining: how do i find out what caused the event? i.e. can i link it to a specific layer?
0 Kudos
JohnHauck
Occasional Contributor II
I'm not seeing a really clean way to do this and not sure if this could meet all of your needs but you could try looking at IContentsView.SelectedItem. You would then need to test to see exactly what the selected item is on ContentsChanged to determine what you would do next.

ILayerEvents can also be used to monitor layer visibility changes but I'm not sure this is really a good fit for your workflow.
0 Kudos