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