Moving layer order

Dec 19, 2010 at 8:13 PM


I'm using visual basic and have added some layers but want to be able to change the order of already loaded layers without removing them and then adding them back in using - is there another way of moving a layer?


Dec 20, 2010 at 5:52 PM

Like any .Net style list, the typical method for re-ordering is to remove and insert in the desired location.  Just remember to call LockDispose() before you remove the layer and UnlockDispose() after you remove the layer or else the removal process will dispose the dataset.  Also, if you are worried about triggering update events, I think you can call "SuspendEvents" and "ResumeEvents" on the layers collection to prevent firing until you have the layers ordered the way you want them.  I don't know if that helps you, but otherwise, there doesn't seem to be an alternate way to reorder .net lists that I know of.




Dec 20, 2010 at 6:55 PM
Thanks, that works perfectly
Jun 22, 2011 at 7:45 AM

I realise the function as below:

public void moveUpLayer()
            if (m_map.Layers.Count>0)
                IMapLayer iMapLayer = GetSelectedLayer();
                if (iMapLayer==null)
                MapLayerCollection mapLayerCollection = m_map.Layers as MapLayerCollection;
                IMapLayer tempLayer = null;
                int SelectedLayerindex = mapLayerCollection.IndexOf(iMapLayer);
                for (int i = 0; i < mapLayerCollection.Count;i++ )
                    if (SelectedLayerindex+1<mapLayerCollection.Count)
                        if (mapLayerCollection[SelectedLayerindex+1]==mapLayerCollection[i])
                            tempLayer = mapLayerCollection[i];
                            mapLayerCollection[i] = iMapLayer;
                            mapLayerCollection[i - 1] = tempLayer;


Is someone can tell me the function above i write is correct?