2

I have been trying to figure this out for almost a full working day and I just can't get it working. All I want to do is fire an event when the user clicks different layers in the ArcMap table of contents.

I can get it working with, for example, the PageLayout using this:

IActiveViewEvents_Event pageLayoutEvent = ArcMap.Document.PageLayout as IActiveViewEvents_Event;

I have Googled and looked into a bunch of different threads, all revolving around the concept of 'IActiveViewEvents_Event'interfaces. I've been able to get the event when the selection changes within the map document itself... But I simply can't get an event to fire in the Table of Contents.

My best attempt looks like this:

IActiveViewEvents toc = ArcMap.Document.get_ContentsView(0) as IActiveViewEvents;
IActiveViewEvents_Event tocEvent = ((TOCCatalogView)toc).SelectedItem as IActiveViewEvents_Event;

However tocEvent is set to null. If I do not cast to IActiveViewEvents_Event, SelectedItem is not null...

If anyone could provide a full example of doing this I would be very grateful!

2

See this question: Event raised when selected layer changes in TOC, but it will unfortunately not be good news for you, as no event of such kind is available in ArcObjects. The answers will provide some hack-ish workarounds which you may find useful.

  • Thanks for the link, that post didn't come up in my searches. I'll explore some of the solutions suggested and let you know how it turns out. – navigator_ Jul 9 '14 at 20:19
  • While we decided to go against the described workarounds and add a button and click event to the add-in instead of selection changed event, your link helped me explain why we had to implement it this way. Thank you. – navigator_ Jul 10 '14 at 14:27
  • Good call I believe. – Petr Krebs Jul 11 '14 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.