AnsweredAssumed Answered

Cannot implicitly convert type 'string' to 'ESRI.ArcGIS.Carto.ILayer'     

Question asked by srbana84 on Nov 15, 2015

Hi

 

I am getting error like "Cannot implicitly convert type 'string' to 'ESRI.ArcGIS.Carto.ILayer'" .

 

 

Please help me how to solve this error.

 

Please find my code below.

 

private void cmdon_Click(object sender, EventArgs e)

        {

 

            ILayer selectedlayer;

            selectedlayer = getlayername(cmblayers.SelectedItem.ToString());

            selectedlayer.Visible = false;

 

 

 

 

        }

 

        private void cmdoff_Click(object sender, EventArgs e)

        {

 

        }

 

        private string  getlayername(string slayername)

        {

           

          

 

             IDocument doc = m_application.Document;

            IMxDocument pmxdoc = doc as IMxDocument ;

 

           

            IMap pmap = pmxdoc.FocusMap;

           

             for (int i = 0; i < pmap.LayerCount; i++)

             {

                 ILayer player = pmap.Layer[i];

 

                 if (player.Name == slayername)

 

 

                     return slayername;

                    

                

                

             }

             return null;

    }

    }

Outcomes