Remove layer LYR from map control

459
2
02-28-2012 01:36 AM
FilippaFideria
New Contributor
Hi forum
I use ArcMap 9.3.1 and ArcObjects, I have created a windows application with a map control.
In the axTOCControl I have added layer lyr with the follow code
 public IFeatureLayer AddLayerLyr(ESRI.ArcGIS.Carto.IActiveView activeView, string layerPathFile, AxMapControl axm)
        {

            //Create a new GxLayer.
            IGxLayer gxLayerCls = new GxLayer();
            IGxFile gxFile = (IGxFile)gxLayerCls;
            //Explicit Cast.

            //Set the path for where the layer file is located on disk.
            gxFile.Path = layerPathFile;

            //Test if you have a valid layer and add it to the map.
            if (!(gxLayerCls.Layer == null))
            {
                IMap map = axm.Map;   // activeView.FocusMap;
                map.AddLayer(gxLayerCls.Layer);
            }
            return ((IFeatureLayer)gxLayerCls.Layer);
        }


Now, how can I remove lyr from toc anc from map?
I would like add code to contex menu or to a button with which delete the selected lyr, how can I do it?

Can you help me please?

Thank you so much!!!
0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
Call IMap::DeleteLayer
0 Kudos
PriyankaMehta
New Contributor
0 Kudos