AnsweredAssumed Answered

IGraphicsContainer.AddElement error

Question asked by spencerrecneps on Mar 5, 2012
Latest reply on Mar 5, 2012 by sshetty
I'm trying to add a new map frame (and accompanying map) to my document's page layout. I'm roughly following the code example from this ESRI example but the process errors out with
Value does not fall within the expected range

Here is the relevant code
            //create the new map with settings             IMap addMap = new Map();             addMap = m_maps.Create();             addMap.Name = scenarioName;             IEnvelope mapExtent = new EnvelopeClass();             mapExtent = (IEnvelope)m_doc.ActiveView.Extent;                          //create new mapframe and set map layout             IMapFrame addMapFrame = new MapFrameClass();             addMapFrame.Map = addMap;             IElement mapFrameElement = (IElement)addMapFrame;             IGraphicsContainer pGC = (IGraphicsContainer)m_doc.PageLayout;             pGC.AddElement(mapFrameElement, 0);

It looks like the AddElement  method doesn't like the integer being passed. I've tried with different int values but still get the same error. What could be causing this error?

Outcomes