By Dave Butz, GIS Software Developer, Riverside, California, USA

Download the script.

Code Summary

This is a demonstration of a custom activeLayer class that I wrote to enable the programmer give the end-user a way to select an "active" or "target" layer. The active layer is the layer that will affected by any other custom tasks the programmer creates. So for example, my demo has a full set of spatial selection tools which feature selection by rectangle, polygon, and point. It also allows the user to select from 'New selection', 'Add to selection', 'Remove from selection', and 'Select from selected'. Instead of selecting features from all layers, the user selects from a dropdownlist the layer they want to be 'active'. Then the spatial selection tool makes use of the custom active layer class and is able to obtain the layer's ID, TOC position, and various other layer properties using a single line of code.

Dim myLayer as activeLayer()= New activeLayer(Map1, localMapResource, ddlActiveLayer.Items(0).Text)

Then you can simply reference all the layers properties you could want:
dim lyrID as integer = myLayer.layerID
dim lyrTOCPosition as integet = myLayer.TOCPosition
dim lyrSelection as ESRI.ArcGIS.ADF.ArcGISServer.FIDSet = myLayer.selectedFeatures
dim myLry as ESRI.ArcGIS.Carto.ILayer = myLayer.layerObject
dim myLyrFeatureClass as ESRI.ArcGIS.Geodatabase.IFeatureClass = myLayer.featureClassObject