IActiveViewEvents_Event not working

2548
4
04-13-2012 07:02 AM
Vamseekonda
New Contributor
Hello,

I am working on an Add-In where I need to wire up events for IActiveViewEvents_Event.ItemAdded and IActiveViewEvents_Event.ItemDeleted. Basically I need to way to execute my code when a layer is added/deleted.

I have tried:
 
m_activeViewEventsEvent = ArcMap.Document.FocusMap as IActiveViewEvents_Event;
m_activeViewEventsEvent.ItemDeleted += new IActiveViewEvents_ItemDeletedEventHandler(m_activeViewEventsEvent_ItemDeleted);
m_activeViewEventsEvent.ItemAdded += new IActiveViewEvents_ItemAddedEventHandler(m_activeViewEventsEvent_ItemAdded);


But the events never fire. This code used to work just fine in 9.3. Has something change in 10.0? Any help will be appreciated.

Thanks,
VK
0 Kudos
4 Replies
SebastianKrings
Occasional Contributor
0 Kudos
Vamseekonda
New Contributor
Sebastian,

No this isn't working. This is actually what I am doing in my code.

VK.
0 Kudos
SebastianKrings
Occasional Contributor
hey

in the snippet this is done:

  // Create an instance of the delegate, add it to ItemAdded event
  m_ActiveViewEventsItemAdded = new ESRI.ArcGIS.Carto.IActiveViewEvents_ItemAddedEventHandler(OnActiveViewEventsItemAdded);
  activeViewEvents.ItemAdded += m_ActiveViewEventsItemAdded;


that differs from what you have posted. Unless you variable "m_activeViewEventsEvent_ItemAdded" is like:
m_activeViewEventsEvent_ItemAdded = OnActiveViewEventsItemAdded;

But "OnActiveViewEventsItemAdded" is a method, the method handler and not a variable. So this method is called when the event is fired.
I do not know if you're working with delegates on "m_activeViewEventsEvent_ItemAdded".

This seem to work for another user (quick google search within first 5 hits):
http://forums.arcgis.com/threads/26019-IActiveView-Events
http://resources.esri.com/help/9.3/ArcGISEngine/dotnet/ViewCodePages/e9d3cad8-0770-466a-a62d-6cd9d05...

Sebastian
0 Kudos
Vamseekonda
New Contributor
Sebastian,

m_activeViewEventsEvent_ItemAdded is not a variable - its a method. Sorry I should rename the method to just activeViewEventsEvent_ItemAdded - sorry dealing with some legacy code here. I will try out the other links. I really appreciate your help.

thanks,

VK
0 Kudos