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!