# Overlays collection

**URL:** <https://community.thinkgeo.com/t/overlays-collection/475>\
**Category:** WinForms\
**Created:** [June 15, 2009, 11:30am UTC](https://community.thinkgeo.com/t/overlays-collection/475 "2009-06-15T11:30:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Charles](https://community.thinkgeo.com/u/Charles)\
**Post date:** [June 15, 2009, 11:30am UTC](https://community.thinkgeo.com/t/overlays-collection/475/1 "2009-06-15T11:30:22Z")

</div>

I&nbsp;am&nbsp;having&nbsp;trouble&nbsp;with&nbsp;the&nbsp;Overlays&nbsp;collection.&nbsp;&nbsp;I&nbsp;am&nbsp;creating&nbsp;LayerOverlays&nbsp;and&nbsp;I&nbsp;add&nbsp;each&nbsp;with&nbsp;a&nbsp;name&nbsp;using&nbsp;code&nbsp;similar&nbsp;to&nbsp;MapWindow.Overlays.Add(MyOverlay,&nbsp;MyOverlay.Name).&nbsp;&nbsp;At&nbsp;a&nbsp;later&nbsp;point&nbsp;I&nbsp;check&nbsp;for&nbsp;the&nbsp;existence&nbsp;of&nbsp;the&nbsp;overlay&nbsp;using&nbsp;code&nbsp;similar&nbsp;to&nbsp;MapWindow.Overlays.Contains(OverlayName)&nbsp;where&nbsp;OverlayName&nbsp;is&nbsp;the&nbsp;same&nbsp;as&nbsp;Overlay.Name&nbsp;above.&nbsp;&nbsp;Unfortunately,&nbsp;the&nbsp;Contains&nbsp;method&nbsp;returns&nbsp;false&nbsp;even&nbsp;though&nbsp;I&nbsp;can&nbsp;see&nbsp;an&nbsp;Overlay&nbsp;with&nbsp;that&nbsp;name&nbsp;in&nbsp;the&nbsp;collection&nbsp;with&nbsp;the&nbsp;Watch&nbsp;window.&nbsp;&nbsp;Am&nbsp;I&nbsp;doing&nbsp;something&nbsp;wrong&nbsp;here?

Charles

---

<div class="post-metadata">

**Author:** ![Charles](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Charles](https://community.thinkgeo.com/u/Charles)\
**Post date:** [June 15, 2009, 11:40am UTC](https://community.thinkgeo.com/t/overlays-collection/475/2 "2009-06-15T11:40:05Z")

</div>

My&nbsp;bad.&nbsp;&nbsp;I&nbsp;had&nbsp;code&nbsp;in&nbsp;two&nbsp;places&nbsp;that&nbsp;added&nbsp;overlays,&nbsp;one&nbsp;with&nbsp;a&nbsp;key&nbsp;and&nbsp;one&nbsp;without.&nbsp;&nbsp;In&nbsp;both&nbsp;places&nbsp;the&nbsp;Overlay&nbsp;name&nbsp;was&nbsp;set,&nbsp;but&nbsp;the&nbsp;overlay&nbsp;couldn't&nbsp;be&nbsp;referenced&nbsp;by&nbsp;a&nbsp;key&nbsp;because&nbsp;it&nbsp;wasn't&nbsp;added&nbsp;with&nbsp;a&nbsp;key.

Charles

---

<div class="post-metadata">

**Author:** ![Charles](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Charles](https://community.thinkgeo.com/u/Charles)\
**Post date:** [June 15, 2009, 11:42am UTC](https://community.thinkgeo.com/t/overlays-collection/475/3 "2009-06-15T11:42:25Z")

</div>

Double&nbsp;posting&nbsp;too.&nbsp;&nbsp;Not&nbsp;a&nbsp;good&nbsp;day.

Charles

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [June 15, 2009, 7:59pm UTC](https://community.thinkgeo.com/t/overlays-collection/475/4 "2009-06-15T19:59:41Z")

</div>

Charles,

Thanks&nbsp;for&nbsp;your&nbsp;post!  
&nbsp;  
I&nbsp;just&nbsp;want&nbsp;to&nbsp;make&nbsp;sure&nbsp;you&nbsp;are&nbsp;using&nbsp;the&nbsp;latest&nbsp;Desktop&nbsp;Edition&nbsp;version(3.0.307&nbsp;RC)?&nbsp;&nbsp;In&nbsp;this&nbsp;version&nbsp;when&nbsp;added&nbsp;overlay&nbsp;to&nbsp;MapControl,&nbsp;it&nbsp;should&nbsp;be:  
&nbsp;  
MapWindow.Overlays.Add(MyOverlay.Name,&nbsp;MyOverlay)  
&nbsp;  
Instead&nbsp;of  
&nbsp;  
MapWindow.Overlays.Add(MyOverlay,&nbsp;MyOverlay.Name)  
&nbsp;  
I&nbsp;tested&nbsp;with&nbsp;following&nbsp;code&nbsp;and&nbsp;it&nbsp;works&nbsp;fine:  
`Overlay overlay1 = new LayerOverlay();Overlay overlay2 = new LayerOverlay();Overlay overlay3 = new LayerOverlay();winformsMap1.Overlays.Add("Overlay1", overlay1);winformsMap1.Overlays.Add("Overlay2", overlay2);winformsMap1.Overlays.Add( overlay3);bool contains1 = winformsMap1.Overlays.Contains("Overlay1");bool contains2 = winformsMap1.Overlays.Contains("Overlay2");`  
One&nbsp;thing&nbsp;I&nbsp;want&nbsp;to&nbsp;point&nbsp;out&nbsp;is&nbsp;that&nbsp;when&nbsp;you&nbsp;added&nbsp;an&nbsp;Overlay&nbsp;without&nbsp;giving&nbsp;it&nbsp;a&nbsp;key,&nbsp;then&nbsp;it&nbsp;will&nbsp;add&nbsp;a&nbsp;GUID&nbsp;as&nbsp;key&nbsp;automatically.  
&nbsp;  
Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;let&nbsp;me&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale
