Is there an event in ArcObjects to determine whether a layer (specifically a shapefile) has been loaded into a map?
I'm using ArcObjects 10.4.1 and C#
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityIs there an event in ArcObjects to determine whether a layer (specifically a shapefile) has been loaded into a map?
I'm using ArcObjects 10.4.1 and C#
The event handler for capturing layers added to the map is IActiveViewEvents.ItemAdded
Make sure its pointing to a Map and not PageLayout.
You would then test to see if it is specifically a shapefile.
Here is some boiler plate code to set up active view events. You'll just need to write a function that checks if the item added is a shapefile. Call that function from Events_ItemAdded().
public static IActiveViewEvents_Event ActiveViewEvent;
private void WireDocumentEvents()
{
// Event handlers
ArcMap.Events.CloseDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_CloseDocumentEventHandler(Events_CloseDocument);
if (ActiveViewEvent == null)
ActiveViewEvent = ArcMap.Document.FocusMap as IActiveViewEvents_Event;
if (ActiveViewEvent == null) return;
ActiveViewEvent.ItemAdded += Events_ItemAdded;
ActiveViewEvent.ItemDeleted += Events_ItemRemoved;
}
private void UnWireDocumentEvents()
{
// Unload Event handlers
ArcMap.Events.CloseDocument -= new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_CloseDocumentEventHandler(Events_CloseDocument);
if (ActiveViewEvent == null) return;
ActiveViewEvent.ItemAdded -= Events_ItemAdded;
ActiveViewEvent.ItemDeleted -= Events_ItemRemoved;
ActiveViewEvent = null;
}
void Events_CloseDocument()
{
//DO SOMETHING WHEN DOCUMENT CLOSES
}
private void Events_ItemAdded(object item)
{
//DO SOMETHING WHEN ITEM ADDED
}
private void Events_ItemRemoved(object item)
{
//DO SOMETHING WHEN ITEM REMOVED
}