Thursday 4 June 2015

c# - Using ArcObjects to stop items from being deleted from Table of Contents?


I am using ArcObjects in a C# addin with ArcGIS 10.3.1 for Desktop.


I'm trying to stop a user from removing certain layers from the Table of contents. I have my listeners setup for IActiveViewEvents_ItemDeletedEventHandler but want to know how/what to capture the layer that is removed? Can this be done, or can I only inform the user that they removed something?



Answer




Thanks to @KirkKuykendall I was able to implement this solution.


 public void On_TOCItemDeleted(object Item)
{
var DeletedLayer = Item as ILayer;

if (DeletedLayer == null)
throw new Exception("Not iLayer file");


var grouplyr = GetGroupByName(ArcMap.Document.FocusMap.Layers, groupname);


grouplyr.Add(DeletedLayer);

ArcMap.Document.UpdateContents();
ArcMap.Document.ActiveView.Refresh();
}

The 'object' passed to the method is the layer being deleted, so I can just re-add to the TOC.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...